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

NSURLCache for NSURLSession background tasks

I'm trying to implement caching in my app, I'm using NSURLSession with background configuration for most of my networking needs and it works great but then I'm adding a cache object the session disregards it and always goes to the server I tried to…
Arkadi
  • 51
  • 1
  • 5
0
votes
1 answer

In UIWebView, how to forcibly cache resources that are 'Pragma:no-cache'?

I'm loading a train schedule URL into a UIWebView. Refreshing is slow due to the page being bloated beyond belief with site-wide CSS, JS, image, and other resources that have their response headers set to Cache-Control:no-cache, no-store,…
Chan
  • 269
  • 1
  • 13
0
votes
1 answer

How to cache http response based on AFNetworking in iOS9?

I've used AFNetworking to get http response from remote server. And remote server will return 304 code when the header of http request contains "if-none-match" and "cache-control" fields. Based on NSURLCache class reference, it has provided request…
Qijin
  • 307
  • 2
  • 13
0
votes
3 answers

Requests delayed up to 1min sometimes in iOS9 nsurlstoraged - NSURLStorageURLCacheDB deleteAllResponses database locked

Since iOS 9 we've been reproducing these huge delay in the app processing the request back/ The app launches fine, View Controllers and everything. I'm able to interact with the app but in some cases it won't load some of all requests. It only…
edsancha
  • 89
  • 9
0
votes
1 answer

Ios Intercept UIWebview request via NSURLCache and replace the response

I'm developing an Epub Reader for Ios, notice that i don't use any epub library and i parse the epub myself. I needed a method for loading resource from epub into the UIWebView, for example images or CSS file ... (resource that requested in the…
mehdok
  • 1,499
  • 4
  • 29
  • 54
0
votes
0 answers

Documents & Data usage 2x times NSURLCache size

I'm using very basic caching for a website heavy app I'm making. To set up the cache, all I'm doing is the following: NSURLCache.sharedURLCache().memoryCapacity = 300 * MB NSURLCache.sharedURLCache().diskCapacity = 300 * MB …
user2844801
  • 1,394
  • 2
  • 12
  • 20
0
votes
1 answer

NSCachedURLResponse ignores HTTPBody

I'm creating a NSMutableURLRequest using this code: NSString *urlString = @"http://192.168.1.111/api"; NSURL *url = [NSURL URLWithString:urlString]; NSString *postBody = [NSString stringWithFormat:@"param=%@", param]; NSData *postBodyData =…
Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
0
votes
1 answer

Setting NSURLRequestCachePolicy and NSURLSession

I'm creating an NSURLSession with a sessionConfiguration where I have explicitly set the requestCachePolicy and URLCache. sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration]; sessionConfiguration.requestCachePolicy =…
Matt
  • 71
  • 3
0
votes
2 answers

Local HTML Cache policy in UIWebView

I have walked through various solution to clear the local image cache in UIWebView, while i trying to load the image in html it atomically displays the previous image(i using the same name to replace the image in template). [[NSURLCache…
Gowtham
  • 117
  • 12
0
votes
1 answer

iOS 8 NSURLCache issue

I'm creating an app where I would like to use cached responses from time to time. I ran into a weird issue related to NSURLCache, more spicifically, if I set NSURLRequestReturnCacheDataDontLoad on my request, I don't get a cached response on iOS 8.…
Georgi
  • 430
  • 7
  • 21
0
votes
1 answer

AFNetworking 2.0 AFHTTPRequestOperationManager CachePolicy not working

I'm trying to make a GET request to a server with an If-Modified-Since header in order to avoid loading identical content. When I make a request I know that the server is sending back a 304 indicating that the content has not changed, but NSURLCache…
sigvaria
  • 78
  • 1
  • 8
0
votes
1 answer

How to load cached requests with AFNetworking 2.0 if app is reopen?

I have been using AFNetworking 2.0. Cache works well if the app is in foreground, or came from background. But when I kill the app and reopen it, cache is cleared. Is there a way to make it persistent? Thanks
Oscar J. Irun
  • 455
  • 5
  • 17
0
votes
2 answers

How to clear cache of app in objective C?

I'm building an iOS app in which i have implemented Fabric and using Digits for login.When login is successful session remains open. I'm facing an issue i want to clear the app cache to reset the session so user can login again with a new phone…
Daljeet
  • 1,573
  • 2
  • 20
  • 40
0
votes
1 answer

UIImageView+AFNetworking Managing Caching & Allocations

I am using the UIImageView+AFNetworkingin order to download and display an image from a URL in a UITableView. Everything is working great and my question is around the caching elements & allocations that are implemented with this call. In using…
0
votes
1 answer

Does the network link conditioner affect NSURLCache's response time?

When the iOS network link conditioner is enabled, will requests cached by the shared NSURLCache be returned more slowly?
ravron
  • 11,014
  • 2
  • 39
  • 66