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
4
votes
1 answer

NSURLCache cachedResponseForRequest doesn't retrieve cached data

I am trying to get the previously cached information from NSURLCache. With this code: NSString *theCompleteURL = @"http://192.168.1.2:8080/api/endpoint.json"; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL…
David Cordero
  • 770
  • 6
  • 16
4
votes
2 answers

UIWebView and NSURLCache have a troubled relationship

I am trying to solve 2 things in my UIWebView: Load local assets in place of remote ones, under the right conditions Load remote assets as normal if there are no local ones or they are outdated Allow the webview to go "back" without needing to…
Alex Wayne
  • 178,991
  • 47
  • 309
  • 337
4
votes
0 answers

Does the iOS Networking Framework (NSURLCache) transparently handle ETags?

We are wondering, whether NSURLCache transparently handles ETag based caching headers. Asked differently: If correctly setting up NSURLCache, will the iOS networking framework automatically "remember ETags per request URI" and add them to request…
Ralf
  • 2,512
  • 4
  • 24
  • 26
4
votes
2 answers

iOS REST calls and caching strategies

I have used a few different strategies in the past to provide the best user experience when going through various screens of a REST based iOS app: leverage NSURLCache: Although this works fine for certain use cases, I am more interested in an…
JP Hribovsek
  • 6,707
  • 2
  • 21
  • 26
4
votes
2 answers

Disk Backed Image Cache for UIImageView in AFNetworking

I'm looking to swap out the AFImageCache used by default in the UIImageView+AFNetworking category for something that's disk based and that can managed a little more accurately (something like NSURLCache). Unfortunately, since…
jpredham
  • 2,149
  • 1
  • 23
  • 37
4
votes
1 answer

NSURLResponse returns Content-Range, ignoring the Range that I asked for

When downloading a file, I want to be able to resume the download. For example: NSFileManager *fm = [NSFileManager defaultManager]; NSString *downloadTempPath = [_tempPath path]; if ([fm fileExistsAtPath:downloadTempPath]) { // We have a…
Skotch
  • 3,072
  • 2
  • 23
  • 43
4
votes
2 answers

NSURLCache crashes under iOS 6.1

Using iOS 6.1 my App crashes regulary, directly after startup, when it attempts to make several HTTP-Requests, but it works fine on any OS < 6.1. I'm experiencing EXC_BAD_ACCESS crashes in the strlen function called from the Queue :…
Ben-G
  • 4,996
  • 27
  • 33
4
votes
2 answers

Is there a way to query the HTML5 application cache?

Is there a way to query the contents of the HTML5 application cache? I'm writing an iOS application that uses a lot of cached web content. Before loading a given page when the app is offline, I'd like to check whether the page exists in the cache.…
Caleb
  • 124,013
  • 19
  • 183
  • 272
4
votes
0 answers

Using NSURLCache to preload local assets for UIWebView

I'm working on an iOS application that displays locally-stored content (HTML files) in a UIWebView. The problem is that some of the assets referenced from the HTMLs (for example fonts and images) take quite a while when loaded for the first time. I…
4
votes
2 answers

Is there on-disk cache available on iPhone?

I found a project to improve the cache strategy on iPhone. Cos they are sure: "On iPhone OS, Apple did remove on-disk cache support for unknown reason" But, I do not think so, see deitail: https://github.com/rs/SDURLCache/issues/39 I found there are…
meadlai
  • 895
  • 1
  • 9
  • 22
3
votes
0 answers

How to use NSCachedURLResponse

I am trying to save different sets of data that is being returned to me via my NSURLConnection methods. this is my connectionDidFinishLoading method, which currently at the moment is passing each separate lot of data over to a parser. As a side not…
C.Johns
  • 10,185
  • 20
  • 102
  • 156
3
votes
1 answer

On-disk storage of NSURLCache in iOS 5?

I've trying to display cached php/javascript content on a UIWebview for a while but I haven't succeeded yet. It runs OK with static content, but as soon as I try to load dynamic content using javascript it fails. I've tried several potential…
3
votes
0 answers

How does NSURLCache work in iOS 4?

When I learn NSURLCache documentation I can't find many important notes. I found that many topics in web complain that NSURLConnection that use NSURLCache had memory leaks. When I tried to write some application for iOS 4.3 I found that MSURLCache…
kostyl
  • 339
  • 3
  • 15
3
votes
1 answer

How to clear cache for a URL in URLCache.shared?

Is it possible to clear the URL Cache for just one url and not the whole cache? I have already tried this put it does not seem to do anything. let url = URL(string: "https://example.com")! let request = URLRequest(url: url) …
Jacob Zyla
  • 225
  • 2
  • 11
3
votes
0 answers

NSURLCache bypasses HTML5 video tag

I have an NSURLCache descendent working with a UIWebView. I load a web page in the WebView and can intercept all of the HTTP requests it makes (and cache locally to the documents directory). This works for inline images, javascript references and…
Simon Lee
  • 22,304
  • 4
  • 41
  • 45