---
title: "getCachedResponse(for:completionHandler:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/urlcache/getcachedresponse(for:completionhandler:)"
---

# getCachedResponse(for:completionHandler:)

Gets the cached URL response for a data task, passing it to the provided completion handler.

## Declaration

```swift
func getCachedResponse(for dataTask: URLSessionDataTask, completionHandler: @escaping @Sendable (CachedURLResponse?) -> Void)
```

```swift
func cachedResponse(for dataTask: URLSessionDataTask) async -> CachedURLResponse?
```

## Parameters

- `dataTask`: The data task whose cached URL response is desired.
- `completionHandler`: A completion handler that receives the cached URL response for the data task’s request, or nil if no response is found in the cache.

## See Also

### Getting and storing cached objects

- [cachedResponse(for:)](foundation/urlcache/cachedresponse(for:).md)
- [storeCachedResponse(_:for:)](foundation/urlcache/storecachedresponse(_:for:)-7p7bl.md)
- [storeCachedResponse(_:for:)](foundation/urlcache/storecachedresponse(_:for:)-8uq91.md)
