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

iOS ajax call from a local html to a local xml resource not working

In my iOS app I am loading a local html file which internally is making an ajax call to a local xml resource which is failing. I am using NSURLCache to intercept the request.
0
votes
0 answers

NSUrlCache removeCachedResponseForRequest:requestImage implementation in objective c

I want to store the response fetched from a request in NSUrlCache.How. How can this be done? -(void)sendRequestForImage { NSCachedURLResponse * cachedResponse = [Cache cachedResponseForRequest:requestImage]; if(!cachedResponse.data) …
Prez
  • 227
  • 3
  • 12
0
votes
0 answers

URLCache don't save CacheURLResponse by request (using Alamofire)

I'm tying to save some response to URLCache: var cache: URLCache = URLCache(memoryCapacity: 4 * 1024 * 1024, diskCapacity: 10 * 1024 * 1024, diskPath: nil) request.response { (dataResponse) in guard let response =…
givip
  • 21
  • 1
  • 3
0
votes
3 answers

iPhone: extracting text from and Disk-Cache of retrieved web page

My iPhone app has an Info page, which contains a UIWebView, which I have pointed at my website's info page: NSString *urlAddress = @"http://www.toneme.org/Software"; NSURL *url = [NSURL URLWithString: urlAddress]; NSURLRequest *requestObj =…
P i
  • 29,020
  • 36
  • 159
  • 267
0
votes
1 answer

Is it possible to use NSURLCache to rate limit outgoing HTTP requests on the client side?

Is it possible to set up a "rate limiting" caching policy using NSURLRequest, NSURLSession and NSURLCache. i.e.Only fire off the same request 1 time in a given time period, perhaps 1 second So if I fire off multiples of the same exact request in a…
Sabobin
  • 4,256
  • 4
  • 27
  • 33
0
votes
1 answer

How should I deal with cache settings?

I am building a SDK targeted at developers in my corporation, both at the head office and abroad. This SDK is implemented as a Singleton and provides the developers with data objects acquired (when possible) from our corporate servers. I intend to…
Kheldar
  • 5,361
  • 3
  • 34
  • 63
0
votes
1 answer

How to load cache data at first and load data from network after

I am new to nsurlcache. And my goal is to show first my cache data and show it to my display and after that, I want to access the network and replace the cache data and reload my display. This is what I'm using: mutableURLRequest.cachePolicy =…
Alvin John
  • 403
  • 4
  • 14
0
votes
1 answer

Linked resources of large size are not cached when loading a page using NSURLRequest from an OSX App

My OSX app is attempting to load a web page inside a webview. I require caching the web page for the faster laoding of the page between successive launches of the app. All the resource files(js/css/images) linked to the page is cached except one js…
0
votes
1 answer

iOS - Batch (coalesce) network requests to a particular resource . Cooperation between NSURLSession , NSURLRequest etc

I have a highly asynchronous environment and many modules which may request a particular network resource (such as an access token and perhaps indirectly through transitive requests). For instance many places in code could "simultaneously" do calls…
Avba
  • 14,822
  • 20
  • 92
  • 192
0
votes
0 answers

Cache image with nsurlcache

I have an image that I'm getting ready to upload. I know that I can download it and store it in the AFNetworking NSURLCache I already have, but I already know the what the url will be before I upload it so I want to cache it before I upload it…
ian
  • 1,002
  • 2
  • 12
  • 29
0
votes
1 answer

iOS Networking data cache issue

I am developing app. It includes login page. After login I receive the response json. I tried the login multiple times with two different accounts. Lets say account A & B. If I build and run fresh build on device and login with account A. I get the…
Ganesh
  • 101
  • 1
  • 11
0
votes
1 answer

Is NSURLCache cleared on iOS app reinstall?

TL;DR:Does anyone know if requests made by an app via AFNetworking/NSURLConnection get stored and persisted in NSURLCache between re-installs of the app? Background: I am troubleshooting a bizarre bug affecting some users of a shipping app, which…
Andrew Ebling
  • 10,175
  • 10
  • 58
  • 75
0
votes
1 answer

iOS How to differentiate a UIWebView's request?

How to differentiate a NSURLRequest between UIWebView and NSURLConnection in NSURLProtocol or NSURLCache? I want to monitor a UIWebView's request without NSURLConnection, how to do? The UIWebView's content has resource: js, image, href. How to…
fyxrhyry
  • 135
  • 1
  • 8
0
votes
1 answer

AFNetworking: Cache.db created but cache-control → no-cache in server response heder

In my iOS app I'm using AFNetworking library to send POST requests to the server. The server response headers contain cache-control → no-cache. In my custom AFHTTPSessionManager subclass I don't explicitly set the NSURLRequestCachePolicy, so I think…
Giorgio
  • 1,973
  • 4
  • 36
  • 51
0
votes
1 answer

NSURLCache with changing Mashery "sig=XXXXXX" query item

Is it possible to use NSURLCache to cache responses when the URL includes a changing query item? For example, we add Mashery's required "sig=XXXXXX" query item, which changes for each request. If not, is there a workaround?
Marco
  • 6,692
  • 2
  • 27
  • 38