I would like to load page first time from web and other time from cache when there is no change in page.
I have some problems with cache.
I paste this code in AppDelegate:
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:20 * 1024 * 1024
diskCapacity:100 * 1024 * 1024
diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
and this how I use request:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:dataURLString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:2*60];
If I stay in app it works fine and page load from cache, but when I close my app and load it again, page load from web again. What I have to do, to load it from cache?
SDURLCache
is a drop in replacement for NSURLCache but does save to disk on iOS 4 and above.
- (void)prepareCache {
SDURLCache *cache = [[SDURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024
diskCapacity:20 * 1024 * 1024
diskPath:[SDURLCache defaultCachePath]];
cache.minCacheInterval = 0;
[NSURLCache setSharedURLCache:cache];
NSLog(@"Cache is being logged to: %@", [SDURLCache defaultCachePath]);
}
MOre info can be found here: