I'm working on a feature to opt in for using protocol cache in the package. Basically, instead of custom in-memory/disk cache, use NSURLCache and NSURLRequest.CachePolicy.
The main reason is that protocol cache supports Cache-Control header. Also you may use another library that caches images in shared NSURLCache.
As a trade-off you lose some control, like in-memory caching, download delays, expiry intervals (that you get with Cache-Control header). It also only properly works for in-memory downloads (using URLSessionDataTask).
URLImageService.shared.defaultOptions.cachePolicy = .useProtocol
// Download using `URLSessionDataTask`
URLImageService.shared.defaultOptions.loadOptions.formUnion(.inMemory)
// Set your `NSURLRequest.CachePolicy`
URLImageService.shared.defaultOptions.urlRequestConfiguration.cachePolicy = .returnCacheDataElseLoad
Please test it and let me know ideas/feedback you have. Cheers!
I'm working on a feature to opt in for using protocol cache in the package. Basically, instead of custom in-memory/disk cache, use
NSURLCache
andNSURLRequest.CachePolicy
.The main reason is that protocol cache supports Cache-Control header. Also you may use another library that caches images in shared
NSURLCache
.As a trade-off you lose some control, like in-memory caching, download delays, expiry intervals (that you get with Cache-Control header). It also only properly works for in-memory downloads (using
URLSessionDataTask
).You can follow development in branch protocol_cache_policy
Here is how to configure the package:
Please test it and let me know ideas/feedback you have. Cheers!