Skip to content

Network Disk Caching

jverkoey edited this page Dec 26, 2011 · 4 revisions

As of 0.9.1 Nimbus will no longer use ASIHTTPRequest for the networkimageview feature. This means that network image views will not automatically cache to disk anymore. It is easy to enable disk caching again by using SDURLCache, an implementation of NSURLCache that provides disk cache support.

To enable network disk caching in your application, add SDURLCache.h and SDURLCache.m to your project and then add the following code to your application delegate:

// Nimbus implements its own in-memory cache for network images. Because of this we don't allocate
// any memory for NSURLCache.
static const NSUInteger kMemoryCapacity = 0;
static const NSUInteger kDiskCapacity = 1024*1024*5; // 5MB disk cache
SDURLCache *urlCache = [[[SDURLCache alloc] initWithMemoryCapacity:kMemoryCapacity
                                                          diskPath:[SDURLCache defaultCachePath]]
[NSURLCache setSharedURLCache:urlCache];

And you're done. Network requests will now automatically cache their responses to disk, respecting the cache headers accordingly.

Something went wrong with that request. Please try again.