I'm using setImageWithURL
to download some images in my app. Is it possible:
- to specify how long this image must be held in cache (eg 1 week)?
- to specify how big the the maximum total size of the cache (eg 200
MB)
- to see what is in the image cache?
- to clear the cache?
The documentation is not really clear on these points..
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];