nsurlcache

AFNetworking 2.0 AFHTTPRequestOperationManager CachePolicy not working

北城余情 提交于 2019-12-25 10:05:08
问题 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 or AFNetworking is responding with a 200 with the cached content. In order to prevent this I set the request serializer's cache policy to NSURLRequestReloadIgnoringLocalCacheData, however this does not solve the problem. - (void)getConfig { /

Local HTML Cache policy in UIWebView

依然范特西╮ 提交于 2019-12-25 05:32:47
问题 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 sharedURLCache] removeAllCachedResponses]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL fileURLWithPath:[[CustomFunctions getFilesPath] stringByAppendingPathComponent:obj]] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData

How to test/check use of NSURLCache?

我与影子孤独终老i 提交于 2019-12-22 20:43:22
问题 I have added the two lines of code to my project as described in this blog post. However, as nothing different happens in the app itself, is there a way to test this behaviour and check it is working as expected? Is there a profile in instruments? Is there something I can print to the log in Xcode when a response is cached/cached response is used? It just seems so simple to implement, I want to make sure it is actually having an effect on my app and that I won't have to implement a caching

Download and cache entire web page on ios

佐手、 提交于 2019-12-22 11:22:05
问题 I need to download an entire webPage and store it in app's documents directory and load it from the cache the next time user visits. No matter how much I search, I always end up with ASIWebPageRequest..!! even though, it works, its very old and deprecated.So I am looking for some alternatives. Another reason I am trying to avoid it is because .... It is a completely reimplemented URL loading system, based on very low level constructs (CFNetwork). So as Apple makes improvements to their high

Why is NSURLSession don't use my configured NSURLCache?

做~自己de王妃 提交于 2019-12-22 05:54:11
问题 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 { NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; config.requestCachePolicy = NSURLRequestUseProtocolCachePolicy; NSURLCache *cache = [[NSURLCache alloc] initWithMemoryCapacity:1024 * 100 diskCapacity:1024 * 100 diskPath:@"test.urlcache"]; NSLog(@"usage:%lu",

How to set the shared URLCache in swift 3?

天大地大妈咪最大 提交于 2019-12-22 01:39:08
问题 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) NSURLCache.setSharedURLCache(sharedCache) 回答1: This works in Xcode 8 Beta 4 URLCache.shared = sharedCache 回答2: Here is an Example in Swift 3 increasing cache size to 500 MB let memoryCapacity = 500 * 1024 * 1024 let diskCapacity = 500 * 1024 * 1024 let cache = URLCache(memoryCapacity:

How to download a web page with it's inner resoures like images,css in iOS?

若如初见. 提交于 2019-12-21 23:47:57
问题 I'm trying to download the specified web pages with their inner page resources to disk. When I send a NSURLRequest, only the initial URL would be request, but the resources as images,css,js would not be download. Someone suggests to use cache, but I don't want to cache every web page browsed in the uiwebview, but only the one I specified.For example, when I input an url to the uiwebview addressbar then click on the "save" button, the page will be saved entire, but the other browsing in the

Mutable NSHTTPURLResponse or NSURLResponse

别说谁变了你拦得住时间么 提交于 2019-12-19 09:56:48
问题 I need to modify response headers in an NSURLResponse. Is this possible? 回答1: I was just talking about this with a friend. My suggestion would be to write a subclass of NSURLResponse. Something along these lines: @interface MyHTTPURLResponse : NSURLResponse { NSDictionary *myDict; } - (void)setAllHeaderFields:(NSDictionary *)dictionary; @end @implementation MyHTTPURLResponse - (NSDictionary *)allHeaderFields { return myDict ?: [super allHeaderFields]; } - (void)setAllHeaderFields:

UIWebView and NSURLCache have a troubled relationship

北战南征 提交于 2019-12-19 03:57:01
问题 I am trying to solve 2 things in my UIWebView : Load local assets in place of remote ones, under the right conditions Load remote assets as normal if there are no local ones or they are outdated Allow the webview to go "back" without needing to reload it's html form the server So to handle #1 and #2, I implemented a custom subclass NSURLCache . It gets called when the webview requests assets, and I can send along the local ones instead, aborting the server call for the asset. I even have a

Alamofire - NSURLCache is not working?

对着背影说爱祢 提交于 2019-12-17 17:58:40
问题 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