How to configure cache when using AFNetworking setImageWithURL

I am using setImageWithURL to upload some images to my application. Is it possible to:

  • to indicate how long this image should be kept in cache (for example, 1 week)?
  • to indicate the maximum total cache size (e.g. 200 MB)
  • to find out what is in the image cache?
  • to clear the cache?

The documentation is actually not entirely clear.

+3
caching objective-c ios5 afnetworking
source share
1 answer

The UIImageView category uses an internal ephemeral cache for high performance in things like UITableView . For a longer-term cache, use a system-wide cache system, namely Peter Steinberger’s plug SDURLCache , a subclass of NSURLCache .

Define it using the following code in the application delegate applicationDidFinishLaunching:withOptions: ::

 SDURLCache *URLCache = [[SDURLCache alloc] initWithMemoryCapacity:1024*1024*2 diskCapacity:1024*1024*20 diskPath:[SDURLCache defaultCachePath]]; [URLCache setIgnoreMemoryOnlyStoragePolicy:YES]; [NSURLCache setSharedURLCache:URLCache]; [URLCache release]; 
+13
source share

All Articles