NSURLCache is a class that is used in ios developing for caching the responses of the URL. It is available in OS X v10.2 with Safari 1.0 installed, available in OS X v10.2.7 and later .
The NSURLCache class implements the caching of responses to URL load requests by mapping NSURLRequest objects to NSCachedURLResponse objects.
It provides a composite in-memory and on-disk cache, and lets you manipulate the sizes of both the in-memory and on-disk portions. You can also control the path where cache data is stored persistently.
In iOS, the on-disk cache may be purged when the system runs low on disk space, but only when your app is not running.
To create a new cache object:
- (instancetype)initWithMemoryCapacity:(NSUInteger)memoryCapacity
diskCapacity:(NSUInteger)diskCapacity
diskPath:(NSString *)path;
Sample Example for creation of new cache:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Set app-wide shared cache (first number is megabyte value)
NSUInteger cacheSizeMemory = 500*1024*1024; // 500 MB
NSUInteger cacheSizeDisk = 500*1024*1024; // 500 MB
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"];
[NSURLCache setSharedURLCache:sharedCache];
}
Question related with this can be tagged using nsurlcache , nscachedurlresponseor nsurl tags
Read more