Is it possible in AFNetworking to cache image on disk for more than session? For example for a week or month. In my project i used SDWebImage and AFNetworking, but few days ago i found that AFNetworking has the same functionality as SDWebImage, so a removed SDWebImage and wrote such code to store image on disk:
for ImageView
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:60];
[imageView setImageWithURLRequest:imageRequest placeholderImage:placeholderImage success:nil failure:nil];
Download image to use in future
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:60];
[[AFImageDownloader defaultInstance] downloadImageForURLRequest:imageRequest success:nil failure:nil];
Get downloaded image
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:60];
UIImage *image = [[AFImageDownloader defaultInstance].imageCache imageforRequest:imageRequest withAdditionalIdentifier:nil];
But all this working only per session, after i loaded all images i turn off internet and restart my app, result - no images in cache.
Also i try to add such code in AppDelegate
:
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:2 * 1024 * 1024
diskCapacity:100 * 1024 * 1024
diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
But i still can't cache images for longer than session. (Sorry for my english)