murze
murze

Reputation: 4103

How to configure the cache when using AFNetworking's setImageWithURL

I'm using setImageWithURL to download some images in my app. Is it possible:

  1. to specify how long this image must be held in cache (eg 1 week)?
  2. to specify how big the the maximum total size of the cache (eg 200 MB)
  3. to see what is in the image cache?
  4. to clear the cache?

The documentation is not really clear on these points..

Upvotes: 3

Views: 4656

Answers (1)

mattt
mattt

Reputation: 19544

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

Set it up with 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];

Upvotes: 13

Related Questions