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 .

nsurlcache
Filter by
Sorted by
Tagged with
28 votes
5 answers
20k views

Clear NSURLConnection cache

Is there a way to clear NSURLConnection cache? I used that to download some strings but I keep getting the same strings even though I changed that from my server.
moeseth's user avatar
  • 1,905
26 votes
3 answers
39k views

How to cache using NSURLSession and NSURLCache. Not working

I have a test app setup and it successfully downloads content from the network even if the user switches apps while a download is in progress. Great, now I have background downloads in place. Now I ...
John Erck's user avatar
  • 9,508
24 votes
5 answers
17k views

Prevent NSURLSession from caching responses

Why does it cache responses. It returns previously fetched responses. It even works if turning off the network connection. Resetting the iOS simulator did not seem to work either. Making a request, ...
Sunkas's user avatar
  • 9,620
24 votes
1 answer
4k views

Transition from RestKit to pure AFNetworking 2.0

I'd been using RestKit for the last two years, but recently I've started thinking about transition from these monolith framework as it seems to be really overkill. Here's my pros for moving forward: ...
yariksmirnov's user avatar
21 votes
1 answer
10k views

Is NSURLCache persistent across launches?

I'm looking for a network caching solution for my iOS application that is persistent across launches. I started to read about NSURLCache, but didn't see any mention regarding persistence. Does anyone ...
Brandon's user avatar
  • 3,006
19 votes
1 answer
3k views

How to know if a NSURLResponse comes from cache?

I set NSURLCache on a specific folder (../../Application Support/Offline so it won't be deleted randomly by the OS), then I send a NSURLRequest with NSURLRequestReturnCacheDataElseLoad policy. How ...
greg3z's user avatar
  • 601
17 votes
3 answers
10k views

How to set the shared URLCache in swift 3?

This is the code we had in Swift 2. What is the Swift 3 version? I don't see a replacement for setShared. let sharedCache: NSURLCache = NSURLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil) ...
Jason Hocker's user avatar
  • 7,067
17 votes
2 answers
9k views

NSURLCache and ETags

Does NSURLCache transparently handle ETags received by server? I mean: does it automatically store ETags for each URL request and then send the appropriate If-None-Match when a request to the same ...
Sirio's user avatar
  • 1,011
17 votes
3 answers
5k views

NSURLCache does not clear stored responses in iOS8

Here is the sample function I call when i need to clear cache and make a new call to URL - (void)clearDataFromNSURLCache:(NSString *)urlString { NSURL *requestUrl = [NSURL URLWithString:urlString]...
nkp's user avatar
  • 181
14 votes
2 answers
15k views

Remove UIWebView's internal cache

I'm showing a web app in an UIWebView, and sometimes the content of pages will change. After content have been changed the app clears the cache. But when I go to a page I've previously visited the ...
Niklas Berglund's user avatar
13 votes
2 answers
6k views

How to use NSURLCache to return cached API responses when offline (iOS App)

I'm hoping someone can shed some light on a few things I've been researching but not making much progress on. I'd like to take advantage of NSURLCache to return cached responses for API calls that I ...
Alfie Hanssen's user avatar
12 votes
5 answers
6k views

On iOS where is the NSURLCache cache stored if diskPath:nil?

I've come across code that looks like this: NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024 diskCapacity:1024 * 1024 * 5 ...
user avatar
11 votes
2 answers
2k views

NSURLCache providing inconsistent results on iOS5, seemingly at random

I've just spent an entirely too long amount of time screaming my head off at NSURLCache, so I offer this bit of advice in the hope that others can avoid my misfortune. It all started off reasonably ...
Zach Lipton's user avatar
  • 1,850
11 votes
3 answers
3k views

iPhone: Performances Differences Between NSURLRequestCachePolicy Settings

When using NSURLRequest on the iPhone, what are the real world performance differences between the various NSURLRequestCachePolicy settings? I am specifically interested in the cache policy's effect ...
TechZen's user avatar
  • 64.4k
10 votes
1 answer
7k views

How to set iOS cache and disk storage size and how does cache get restored from disk storage after app termination?

I've already asked When exactly do things get removed from urlcache's memory and disk? Now I have some more follow up questions: The memory cache is restricted by the iPhone's ram (usually 2Gb)....
mfaani's user avatar
  • 34.8k
9 votes
6 answers
12k views

Alamofire - NSURLCache is not working?

I set my cache as below var cacheSizeMemory = 20 * 1024 * 1024 var cacheSizeDisk = 100 * 1024 * 1024 var sharedCache = NSURLCache(memoryCapacity: cacheSizeMemory, diskCapacity: cacheSizeDisk, ...
aryaxt's user avatar
  • 77.1k
9 votes
4 answers
4k views

NSURLConnection on iOS doesn't try to cache objects larger than 50KB

Despite Apple's documentation indicating otherwise, NSURLCache on iOS doesn't do any disk (flash) caching at all. You can subclass NSURLCache to change the behaviour of the fetch and store operations ...
Ben Hoyt's user avatar
  • 10.9k
9 votes
2 answers
1k views

What caching algorithm does NSURLCache use?

Apple's NSURLCache class has decent documentation, but it doesn't say what caching algorithm it uses. Is it LRU, LFU, or something else entirely? I'm developing for the iPad, and am hoping to make ...
Ben Hoyt's user avatar
  • 10.9k
9 votes
1 answer
688 views

NSURLCache does not work when response header value for transfer-encoding is chunked

I found an issue with (possibly) NSURLCache today while inspecting request and response headers in Charles Proxy. The issue is a little perplexing, but I'm able to repro it consistently: In a ...
rainypixels's user avatar
8 votes
4 answers
7k views

Pre-cache Images for AFNetworking's UIImageView category

When my app loads, I pull down a JSON representation of 99 objects. Each object has an 'image_url' field, which I pass to AFNetworking's setImageWithURLRequest. My images load in a tableView, and ...
djibouti33's user avatar
  • 12.1k
8 votes
2 answers
3k views

NSURLCache not caching

So I have subclassed NSURLCache and every time I call loadHTMLFromString: it calls storeCachedRequest:forRequest: and then cachedResponseForRequest:. Here's what I have: - (NSCachedURLResponse *)...
adit's user avatar
  • 33.2k
8 votes
2 answers
2k views

clearing a webviews cache for local files

I've found some similar posts, but they don't seem to have any effect with what I'm doing. I've got a UIWebView that I'm using to display local content in my bundle. Specifically I'm displaying a docx ...
user675446's user avatar
7 votes
1 answer
6k views

How to clear cached data stored by URLSession/URLConfiguration?

I am using the code below to set the caching policy of my URLSession via URLConfiguration. if appDelegateObj.configuration == nil { appDelegateObj.configuration = URLSessionConfiguration....
Umar Farooque's user avatar
7 votes
3 answers
2k views

NSURLCache caching random responses that should not be cached

I am implementing an app which does a lot of networking calls to a rest-api that we also control. Recently we decided to introduce caching headers on the server side to save some valuable networking ...
Angel G. Olloqui's user avatar
7 votes
1 answer
4k views

NSCachedURLResponse returns object, but UIWebView does not interprets content

I am sending a request to a UIWebView. There are AJAX-calls on the loaded webpage. I need to analyze the AJAX-traffic in order to determinate, if the user is logged in or not. For doing this I ...
nodepond's user avatar
  • 501
7 votes
1 answer
11k views

nsurlconnection asynchronous request

First of all the questions are failry simiple.. if you just want to see what they are skip to the bottom of this post and you will see them in bold.. for more detail then you can read the rest of this ...
C.Johns's user avatar
  • 10.2k
7 votes
1 answer
851 views

NSURLCache and Data Protection

I am trying to protect sensitive data stored in NSURLCache. My app's files and Core Data sqlite files are set to NSFileProtectionComplete. However, I am unable to change the NSURLCache files data ...
PPierson's user avatar
  • 408
6 votes
3 answers
1k views

Is NSURLCache thread safe?

I know NSCache is thread safe, however I can't find out any document mentioned that NSURLCache is thread safe.
Pei's user avatar
  • 460
6 votes
1 answer
4k views

Shared NSURLCache and UIWebView on iOS 8

In iOS 7, I was able to set a shared URL cache to a subclass of NSURLCache and any UIWebViews I created would automatically use that shared cache for each request. // Set the URL cache and leave it ...
Jon Willis's user avatar
  • 6,993
6 votes
3 answers
7k views

How do I invalidate iOS's cache for a particular URL?

Using NSURLSession's default caching, how do I invalidate the cache for a particular URL? I note NSURLCache's removeCachedResponseForRequest: method, but that takes an NSURLRequest object, which I ...
Robert Atkins's user avatar
6 votes
2 answers
3k views

NSURLCache, together with NSURLSession, does not respect: Cache-Control: max-age:86000, private, must-revalidate

In AppDelegate.m, I configured: NSURLCache *sharedURLCache = [[NSURLCache alloc] initWithMemoryCapacity:20 * 1024 * 1024 diskCapacity:100 * 1024 * 1024 diskPath:@"FhtHttpCacheDir"]; Then the http ...
foresightyj's user avatar
  • 2,066
6 votes
3 answers
2k views

URLresponse is not retrieved after storing in cache using storeCachedResponse

Goal I'm trying to inject data/response from URLRequest into another URLRequest in my cache. Setup This is just a sample code. It's ready to be dumped into a project. What I'm trying to do is use ...
mfaani's user avatar
  • 34.8k
6 votes
1 answer
1k views

What is the better way to encrypt NSURLCache?

I want to encrypt/decrypt all cached data from a NSURLSession using AES256. I'm new using Alamofire but I think it is possible to do it without involving the library itself. I don't know exactly what ...
emenegro's user avatar
  • 6,941
6 votes
1 answer
2k views

When exactly do things get removed from urlcache's memory and disk?

let memoryCapacity = 200 * 1024 * 1024 let diskCapacity = 1 * 1024 * 1024 let cache = URLCache(memoryCapacity: memoryCapacity, diskCapacity: diskCapacity, diskPath: "myDataPath") URLCache.shared = ...
mfaani's user avatar
  • 34.8k
6 votes
1 answer
3k views

WKWebView and NSURLCache to serve local content

My app loads a very big webapp inside a UIWebView. I have written a NSURLCache extension "LocalCache". This LocalCache extension intercepts my webapp loading, and serves all requested files from a ...
rupps's user avatar
  • 9,772
6 votes
1 answer
5k views

Preventing UIWebView to allocate memory indefinitely (NSURLCache apparently not working)

I have been trying to understand how the UIWebView cache works. Since my goal is to be able to manage the memory allocated by the UIWebView (at least, as much as possible), to avoid memory raising ...
veducm's user avatar
  • 5,943
6 votes
1 answer
830 views

Does NSURLCache remove expired cached responses?

Apple has supported disk caching as of iOS 5.0. I was using a home-rolled solution before, but I'm testing NSURLCache in hopes of finally using it since I've seen strange behavior in the past. One of ...
goldierox's user avatar
  • 1,085
5 votes
1 answer
7k views

URLCache (iOS). storeCachedResponse works asynchronously. How to catch the completion?

Just discovered that the function storeCachedResponse(_ cachedResponse: CachedURLResponse, for request: URLRequest) works asynchronously. That is, the result is not returned immediately after ...
Дмитрий Акимов's user avatar
5 votes
1 answer
782 views

iOS URLCache caching when it shouldn't (IMHO)

Does anyone know why this request is being cached? I'm using an unmodified .default URLSessionConfiguration. The response headers are: (from Charles, confirmed from debugging the response in the ...
deanWombourne's user avatar
5 votes
2 answers
5k views

Why is NSURLSession don't use my configured NSURLCache?

iOS7 brings NSURLSession, with the help of NSURLSessionConfigure, we can customize URLCache, so i tried it, but with no luck, it seems my URLCache is not used at all. - (void)testURLCache { ...
limboy's user avatar
  • 3,989
5 votes
1 answer
3k views

Unit tests with NSURLSession

I'd like to write unit tests for methods that use the shared NSURLSession, and in particular, NSURLSessionDataTask to download data. Basically, I would like the target methods to receive mock ...
hpique's user avatar
  • 120k
5 votes
1 answer
2k views

How to use cache policy NSURLRequestReloadRevalidatingCacheData

The links below iOS - Download file only if modified (NSURL & NSData) http://nshipster.com/nsurlcache/ mentions that NSURLRequestReloadRevalidatingCacheData is not yet implemented in iOS 7. Is ...
Ted's user avatar
  • 23.4k
5 votes
1 answer
252 views

When I use NSCachedURLResponse,I got "301PermMove"

when I test NSURLCache,I got "301PermMove",this is my code -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NSURL *url = [NSURL URLWithString:@"https://www.github....
hmxxxhhh's user avatar
5 votes
1 answer
1k views

Automatically expire NSURLCache with max-age=0

I am using NSURLCache with AFNetworking. Caching works fine but there is no way to check if a response was actually retrieved from cache. To check if a cached version is available, I use [[...
alex's user avatar
  • 4,962
5 votes
2 answers
2k views

NSURLCache not storing cached data in iOS 7

Below given code works in iOS 6 but it does not work on iOS 7. NSCachedURLResponse cachedURLResponse = [[NSCachedURLResponse alloc] initWithResponse:response data:data userInfo:nil storagePolicy:...
Ratan's user avatar
  • 1,747
5 votes
1 answer
3k views

NSURLCache crashes with autoreleased objects, but leaks otherwise

CSURLCache is designed to cache resources for offline browsing, as NSURLCache only stores data in-memory. If cachedResponse is autoreleased before returning the application crashes, if not, the ...
Oliver White's user avatar
5 votes
0 answers
223 views

Share an instance of NSURLCache between an app and extension in a Swift framework

I want to share an instance of NSURLCache between my app and an extension so tried instantiating it from a Swift framework. Is there any way to spawn the URL cache on a shared (container) disk space?
julien_c's user avatar
  • 4,982
5 votes
0 answers
2k views

NSURLCache does not work offline with UIWebVIew

I am trying to load UIWebView Offline with data from NSURLCache. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // setup cache ...
Kunal Balani's user avatar
  • 4,779
5 votes
0 answers
2k views

Weird WebThread Crash in iOS

I'm getting a strange crash in the webthread, happening when releasing a URLResponse. I did not directly manipulate the contents of the URLCache, so what could be the cause of this problem? Here's ...
futureelite7's user avatar
  • 11.5k
5 votes
1 answer
1k views

Use NSURLConnection cache when device is offline

In an NSOperation subclass, I am using the following code to download an xml-file from our server, and then later parse it: NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:...
vtim's user avatar
  • 101

1
2 3 4 5 6