| | |
| | | import Foundation |
| | | |
| | | /// A type that handles whether the data task should store the HTTP response in the cache. |
| | | public protocol CachedResponseHandler { |
| | | public protocol CachedResponseHandler: Sendable { |
| | | /// Determines whether the HTTP response should be stored in the cache. |
| | | /// |
| | | /// The `completion` closure should be passed one of three possible options: |
| | |
| | | /// response. |
| | | public struct ResponseCacher { |
| | | /// Defines the behavior of the `ResponseCacher` type. |
| | | public enum Behavior { |
| | | public enum Behavior: Sendable { |
| | | /// Stores the cached response in the cache. |
| | | case cache |
| | | /// Prevents the cached response from being stored in the cache. |
| | | case doNotCache |
| | | /// Modifies the cached response before storing it in the cache. |
| | | case modify((URLSessionDataTask, CachedURLResponse) -> CachedURLResponse?) |
| | | case modify(@Sendable (_ task: URLSessionDataTask, _ cachedResponse: CachedURLResponse) -> CachedURLResponse?) |
| | | } |
| | | |
| | | /// Returns a `ResponseCacher` with a `.cache` `Behavior`. |
| | |
| | | /// |
| | | /// - Parameter closure: Closure used to modify the `CachedURLResponse`. |
| | | /// - Returns: The `ResponseCacher`. |
| | | public static func modify(using closure: @escaping ((URLSessionDataTask, CachedURLResponse) -> CachedURLResponse?)) -> ResponseCacher { |
| | | public static func modify(using closure: @escaping (@Sendable (URLSessionDataTask, CachedURLResponse) -> CachedURLResponse?)) -> ResponseCacher { |
| | | ResponseCacher(behavior: .modify(closure)) |
| | | } |
| | | } |