CachedResponseHandler
public protocol CachedResponseHandler : Sendable
A type that handles whether the data task should store the HTTP response in the cache.
-
Determines whether the HTTP response should be stored in the cache.
The
completionclosure should be passed one of three possible options:- The cached response provided by the server (this is the most common use case).
- A modified version of the cached response (you may want to modify it in some way before caching).
- A
nilvalue to prevent the cached response from being stored in the cache.
Declaration
Swift
func dataTask(_ task: URLSessionDataTask, willCacheResponse response: CachedURLResponse, completion: @escaping (CachedURLResponse?) -> Void)Parameters
taskThe data task whose request resulted in the cached response.
responseThe cached response to potentially store in the cache.
completionThe closure to execute containing cached response, a modified response, or
nil.
-
cacheExtension methodProvides a
ResponseCacherwhich caches the response, if allowed. Equivalent toResponseCacher.cache.Declaration
Swift
public static var cache: ResponseCacher { get } -
doNotCacheExtension methodProvides a
ResponseCacherwhich does not cache the response. Equivalent toResponseCacher.doNotCache.Declaration
Swift
public static var doNotCache: ResponseCacher { get } -
modify(using:Extension method) Creates a
ResponseCacherwhich modifies the proposedCachedURLResponseusing the provided closure.Declaration
Swift
public static func modify(using closure: @escaping (@Sendable (URLSessionDataTask, CachedURLResponse) -> CachedURLResponse?)) -> ResponseCacherParameters
closureClosure used to modify the
CachedURLResponse.Return Value
The
ResponseCacher.
View on GitHub
Install in Dash