Is it possible in AFNetworking to cache an image on disk more than a session? For example, during the week or month. In my project, I used SDWebImage and AFNetworking , but a few days ago I found that AFNetworking has the same functionality as SDWebImage , so the remote SDWebImage wrote this code to store the 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 for future reference
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60]; [[AFImageDownloader defaultInstance] downloadImageForURLRequest:imageRequest success:nil failure:nil];
Get uploaded image
NSURLRequest *imageRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60]; UIImage *image = [[AFImageDownloader defaultInstance].imageCache imageforRequest:imageRequest withAdditionalIdentifier:nil];
But all this works only for the session, after I downloaded all the images, I turned off the Internet and restarted the application, the result was no images in the cache.
I am also trying to add code like this 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 a session. (Sorry for my English)
source share