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

Simple NSURLCache Implementation on iOS8

I'm having trouble getting a simple implementation of NSURLCache working on iOS8. It's my understanding that once a shared cache is created, it automatically caches data requests with the proper cache policy. No configuration required unless you…
Ja5onHoffman
  • 642
  • 8
  • 17
0
votes
1 answer

iOS NSURLCache making up HTTP 404 when going through NSURLProtocol

If you are serious about answering this question, please clone the mini app i have created and see if it misbehaves for you the same way, before speculating about the answer, thank you :) https://github.com/pavel-zdenek/nsurlprotocol-testbed A very…
Pavel Zdenek
  • 7,146
  • 1
  • 23
  • 38
0
votes
1 answer

NSURLRequest - get a cached response AND a current response?

Before I continue writing my own infrastructure - is it possible to execute a request, have it return immediately if it's cached, and then return later if the cached version does not match the current version? Is that kind of functionality built-in…
xtravar
  • 1,321
  • 11
  • 24
0
votes
3 answers

UIwebview does not clear cache in iOS 7

I am working on an app where few HTML,CSS files are downloaded from the server and loaded in the webview like this [[NSURLCache sharedURLCache] removeAllCachedResponses]; NSURL *url = [NSURL fileURLWithPath:htmlfile]; htmlLoadRequest =…
0
votes
1 answer

How do I share Safari's NSURLCache store?

Background I'm building an app that links recent web pages you've visited together. To do this, I need to get the HTML for recent URLs using Cocoa. Right now, I'm using an invisible WebView to do this. As I understand it, if the URL isn't in the…
John Gallagher
  • 6,208
  • 6
  • 40
  • 75
0
votes
1 answer

curious about NSURLCache

I'm curious about NSURLCache, NSURLRequest has some policy of cache, like NSURLRequestUseProtocolCachePolicy, NSURLRequestReturnCacheDataElseLoad, but after read them, either of them are using local cache data, or not using cache, My question is if…
NickYu
  • 594
  • 1
  • 5
  • 13
0
votes
1 answer

NSURLCache for UIWebview in iOS

I have a mobile site for which I am creating a native app. I am mainly using a UIWebView to load the pages from my mobile site in the app. I want to make the app more responsive. The site isn't heavy on images but has a few HTML forms and stuff. It…
tbag
  • 1,268
  • 2
  • 16
  • 34
0
votes
0 answers

dataWithContentsOfURL stores data in cache but not using it when using NSURLCache

I know there're many similar questions in stackoverflow already, but they still don't clearly explain what I'm seeing. I used [NSData dataWithContentsOfURL:...] with NSURLCache setup and confirmed that it actually stores data in cache. (I opened…
Todd
  • 239
  • 2
  • 11
0
votes
1 answer

how to cache n reload cached data in uiwebview

My UIWebView is getting reloaded everytime with realtime data, I want to cache the UIWebView data at the first time n for each restart or other cases want to reload the UIWebView with dat cached data, unless there is an update required. I've tried…
SoumiMaiti
  • 91
  • 10
0
votes
1 answer

Preventing iOS NSURLCache from storing data

I'm writing a Cordova app, which is configured to use a NSURLCache. For security reasons, I'd like to prevent certain requests and responses from being written to disk. How can I do this? (My concern is not about reusing cached data in subsequent…
JW.
  • 50,691
  • 36
  • 115
  • 143
0
votes
1 answer

NSURLCache doesn't work

I initialized NSURLCache in my app delegate like so: int cacheSizeMemory = 4*1024*1024; // 4MB int cacheSizeDisk = 32*1024*1024; // 32MB MyServerCache *sharedCache = [[MyServerCache alloc] initWithMemoryCapacity:cacheSizeMemory…
HackyStack
  • 4,887
  • 3
  • 22
  • 28
0
votes
1 answer

Ajax NSURLCache Issue still gets undefined response

Hey I have Checked the web and tried all over the suggested solutions but still get UNdefined const NSString *kAppHost = @"myApp.example.org"; - (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *)request { NSURL *url = [request…
user784625
  • 1,928
  • 5
  • 24
  • 38
0
votes
2 answers

unable to configure NSURLCache with more than 2GB discCapacity

I am trying to configure NSURLCache with the maximum disc capacity possible. I'm on iOS 7. according to the docs, NSURLCache's discCapacity attribute is a NSUInteger, aka unsigned int, which should accept a maximum value of 4,294,967,295…
Reneli
  • 1,756
  • 2
  • 16
  • 26
0
votes
0 answers

Trying to understand NSURLCache and why I keep consuming memory

My app makes a lot of URL requests (calling a web service) in a loop for an extended period of time. When I watch the app in the Allocations tool, I see memory consumption going up continuously during the run of that loop. For testing purposes,…
0
votes
1 answer

preload NSURLCache with diskPath location to cache files

Looking for some insight on if this is possible or not. I am trying preload my NSURLCache with a Cache.DB that is already filled with caches from a uiwebview. I don't see why this can't be possible since the Apple documentation states that the…
sudo
  • 1,648
  • 1
  • 20
  • 22
1 2 3
17
18