-
Notifications
You must be signed in to change notification settings - Fork 104
Caching across app launches #8
Comments
There is a separate memory cache ( From the official documentation:
Make sure the HTTP caching is implemented properly. |
disk caching would be a great addition to this excellent library 👍 |
After reading @kean's reply above and digging into the code, DFImageManager does support disk caching, through NSURLSession/NSURLCache. The issue is that DFImageManager calls NSURLSessionConfiguration.defaultSessionConfiguration() which by default has disk cache disabled. After doing some further research, this can be solved 1 of 2 different ways:
The key is the NSURLSessionConfiguration Not too incredibly painful, but since the primary purpose of this app is image caching, it would be nice if there were a simpler way to set that flag perhaps through a property on DFImageManager. |
thanks @bonebox |
Thank you @bonebox. I've added this question to the FAQ These are indeed two intended ways to control image caching:
You can also control request cache policy per request (DFImageRequest) by using DFURLRequestCachePolicyKey (see docs for more info)
This is not entirely true, the default NSURLSessionConfiguration.defaultSessionConfiguration() is initialized with NSURLRequestUseProtocolCachePolicy, which enables HTTP cache policy.
Yep, maybe in the future, just not a single flag but an easier way to provide your own NSURLSessionConfiguration. |
From Apple's official documentation:
This line in particular:
I didn't see that DFImageManager is using NSCachedURLResponse anywhere. Even if it is, from the rest of the documentation it appears that the image headers need to be set appropriately in order for NSURLRequestUseProtocolCachePolicy to cache to disk by default. |
It is used by NSURLCache. Caching is completely transparent in NSURLSession, that's why it's not visible in DFImageManager.
Yep, most servers already do that anyway. It's extremely important because browsers rely on HTTP cache. Our team uses |
I'm using a DFImageView in a UICollectionViewCell and calling the setImageWithResource: method. The caching seems to work as long as my app is open, but every time I restart the app it downloads the images again remotely. Is there some additional configuration needed to make the cache persist across app launches?
The text was updated successfully, but these errors were encountered: