Questions tagged [nsurlcache]

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 , or tags

Read more

267 questions
0
votes
2 answers

How to prevent the browser cache interfering with NSURLCache?

I am trying to achieve the following on iOS: Always load local files to a UIWebView for static assets (.html, .js, etc.) Allow an update protocol such that after some period of time we can return a different set of static assets for the same…
Mike Kwan
  • 24,123
  • 12
  • 63
  • 96
0
votes
1 answer

NSURLRequest: Always getting NSCachedURLResponse back.

I'm using AfNetworking, I make a call for new data but I keep getting the cached result back. So if I'm in a VC that's shows the data, pop back to the root and change data on my server, I then wait 30sec and when I push back into the VC I'll see the…
BooRanger
  • 1,516
  • 1
  • 14
  • 18
0
votes
1 answer

NSURLCache not used by NSURLConnection / AFNetworkingOperation

When I start a request with the NSURLRequestReturnCacheDataElseLoad policy I expect to get the result from the NSURLCache if any, no matter how old it is. However, the system always tries to reach the server the request points to and returns an…
Michael Ochs
  • 2,846
  • 3
  • 27
  • 33
0
votes
1 answer

NSURLConnectionDelegate's connection:willCacheResponse: randomly called

Here is the really simple call I make : NSURL *url = [NSURL URLWithString:urlString]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:500]; NSURLConnection *connection =…
greg3z
  • 601
  • 6
  • 18
0
votes
1 answer

Loading multiple images from the webservice faster

I want to load multiple images from the JSON webservice to my app. These images serve as thumbnails to a "Store" in my app. So when the user clicks a button to go to the "Store", a request is being made. And this request is repeated every time the…
Anna Fortuna
  • 1,071
  • 2
  • 17
  • 33
0
votes
1 answer

Use data from NSURLCache

I have setup an NSURLCache and set the sharedcache to the initialized cache. I can see the cache size growing when I log the size in the NSURLConnection delegates. For some reason when requesting the same data, a request is made to the server again,…
some_id
  • 29,466
  • 62
  • 182
  • 304
0
votes
1 answer

Extend NSURLCache cannot use parameter

I have a class URLCache extends NSURLCache in URLCache.m + (void)initialize { NSString *_cacheSubFolder = nil; NSUInteger _cleanCacheFilesInterval; if (_pageType == FirstPage) { _cleanCacheFilesInterval =…
Jason Zhao
  • 1,278
  • 4
  • 19
  • 36
0
votes
1 answer

NSURLRequest apparently cached in Cache.db but requested again

I am using this block for a synchronous image downloading in an iOS 5 app. The logic is simple, if image is in cache use it, if not download it, I suppose NSURLRequestReturnCacheDataElseLoad has exactly this behavior. …
Leonardo
  • 9,607
  • 17
  • 49
  • 89
0
votes
1 answer

NSURLCache don't support file://?

I would like to load [NSURL fileURLWithPath:@"2.html"] in UIWebView use NSURLCache, the cachedResponseForRequest: function is executed and return a NSCachedURLResponse object which is performed correctly at http:// scheme. But The UIWebView load…
Frank
  • 13
  • 5
0
votes
1 answer

How to tell whether NSURLConnection has cached a certain image?

How would I go about finding out whether a UIImage has already been cached with NSURLConnection? example: if([NSURLCache containsObject:[UIImage imageNamed@"testPic.png"]]){ NSLog(@"item already cached!"); } obviously the above code doesn't work…
Praxder
  • 2,315
  • 4
  • 32
  • 51
0
votes
2 answers

NSURLRequest memory size for cache in iOS

Is the memorySize you specify for the cache (memory) mapped to the disk or is it real memory that is being used?
John Lane
  • 1,112
  • 1
  • 14
  • 32
-1
votes
1 answer

NSURLCache not being used

I am attempting to use NSURLCache so that my app will save JSON responses from a web server and not request it so much. I have added Cache-Control:Max-Age=604800 to the response headers in the request. I have added the following code my apps…
samiles
  • 3,768
  • 12
  • 44
  • 71
1 2 3
17
18