nsurlcache

NSURLCache: inconsistent behaviour

半城伤御伤魂 提交于 2019-11-28 10:36:59
问题 I was observirng some strange behaviour of my app sometime caching responses and sometime not caching them (all the responses have Cache-Control: max-age=600). The test is simple: I did a test.php script that was just setting the headers and returning a simple JSON: <?php header('Content-Type: application/json'); header('Cache-Control: max-age=600'); ?> { "result": { "employeeId": "<?php echo $_GET['eId']; ?>", "dateTime": "<?php echo date('Y-m-d H:i:s'); ?>'" } } This is the response I get

How to use NSURLSession to determine if resource has changed?

依然范特西╮ 提交于 2019-11-28 09:34:13
I'm using NSURLSession to request a JSON resource from an HTTP server. The server uses Cache-Control to limit the time the resource is cached on clients. This works great, but I'd also like to cache a deserialized JSON object in memory as it is accessed quite often, while continuing to leverage the HTTP caching mechanisms built into NSURLSession. I'm thinking I can save a few HTTP response headers: Content-MD5 , Etag , and Last-Modified along with the deserialized JSON object (I'm using those 3 fields since I've noticed not all HTTP servers return Content-MD5 , otherwise that'd be sufficient

NSURLCache and ETags

最后都变了- 提交于 2019-11-28 08:25:16
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 URL is submitted? Or do I have to manage it by myself? yes it does handle it transparently if you set its cache mode: NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy: NSURLRequestUseProtocolCachePolicy timeoutInterval:60]; note: you cannot see the header in the request at all and if a 304 response is returned by the server you will only

Alamofire - NSURLCache is not working?

岁酱吖の 提交于 2019-11-28 06:06:05
I set my cache as below var cacheSizeMemory = 20 * 1024 * 1024 var cacheSizeDisk = 100 * 1024 * 1024 var sharedCache = NSURLCache(memoryCapacity: cacheSizeMemory, diskCapacity: cacheSizeDisk, diskPath: "SOME_PATH") NSURLCache.setSharedURLCache(sharedCache) Create request with cache policy var request = NSMutableURLRequest(URL: NSURL(string: "\(baseUrl!)\(path)")!, cachePolicy: .ReturnCacheDataElseLoad, timeoutInterval: timeout) Make a request and get a response with following Cache-Control private, max-age=60 Then try to check the cache var cachedResponse = NSURLCache.sharedURLCache()

How to cache using NSURLSession and NSURLCache. Not working

巧了我就是萌 提交于 2019-11-28 04:09:42
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 want to add caching. There is no point to me downloading images more than once, b/c of system design, given an image URL I can tell you the content behind that URL will never change. So, now I want to cache the results of my download using apple's built in in-memory/on-disk cache that I've read so much about (as opposed to me saving the file manually in NSCachesDirectory and then checking there

URLresponse is not retrieved after storing in cache using storeCachedResponse

て烟熏妆下的殇ゞ 提交于 2019-11-27 15:42:14
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 the response + data retrieved from my landscapeURLString network request...store into my session's cache for my lizardURLString request. import UIKit class ViewController: UIViewController { lazy var defaultSession : URLSession = { let urlCache = URLCache(memoryCapacity: 500 * 1024 * 1024, diskCapacity: 500 * 1024 * 1024, diskPath: "something") let configuration = URLSessionConfiguration.default

Prevent NSURLSession from caching responses

冷暖自知 提交于 2019-11-27 14:45:34
问题 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, then again with internet offline does work (cached). public let urlSession: NSURLSession public init() { // ... var configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.requestCachePolicy = NSURLRequestCachePolicy.ReloadIgnoringLocalCacheData urlSession =

How to cache using NSURLSession and NSURLCache. Not working

五迷三道 提交于 2019-11-27 05:17:41
问题 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 want to add caching. There is no point to me downloading images more than once, b/c of system design, given an image URL I can tell you the content behind that URL will never change. So, now I want to cache the results of my download using apple's built in in-memory/on-disk cache that I've read so

NSURLCache does not clear stored responses in iOS8

爷,独闯天下 提交于 2019-11-27 03:12:26
问题 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]; NSURLRequest *dataUrlRequest = [NSURLRequest requestWithURL: requestUrl]; NSURLCache * cache =[NSURLCache sharedURLCache]; NSCachedURLResponse* cacheResponse =[cache cachedResponseForRequest:dataUrlRequest]; if (cacheResponse) { NSString* dataStr = [NSString stringWithUTF8String:[[cacheResponse

Remove UIWebView's internal cache

不打扰是莪最后的温柔 提交于 2019-11-27 02:41:31
问题 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 UIWebView doesn't send a HTTP GET request, but loads from cache even though I've disabled cache like so: [[NSURLCache sharedURLCache] removeAllCachedResponses]; [[NSURLCache sharedURLCache] setDiskCapacity:0]; [[NSURLCache sharedURLCache] setMemoryCapacity:0]; Initally I'm loading a request with