-
Notifications
You must be signed in to change notification settings - Fork 97
Advanced Image Caching Guide
Preliminary: Image Caching Guide
DFImageManager has two separate cache storages. The first one is NSURLCache for on-disk caching which handles revalidation transparently (via NSURLSession classes). The second one is NSCache memory storage of decompressed images (instances of UIImage class). NSCache doesn't have any built-in revalidation techniques, however, it automatically removes cached objects when the cache is full and when the application enters background. For most applications that's all the "revalidation" they need, but there might be cases that require a little more control.
NSCache doesn't remove cached objects until the cache is either full or the application enters background. It is possible that the cached object will stay in cache for a very long period of time. There are at least two things you could do to counter this situation.
First, DFImageManager doesn't just use NSCache for in-memory caching - it uses DFImageCache that adds additional functionality to NSCache. One of the DFImageCache features is the time-based cached objects expiration. You can set an maximumEntryAge to prevent cached objects from staying in cache for a long period of times (for example, you might want to revalidate user avatars every 60 seconds).