nsurlcache

How to test/check use of NSURLCache?

六月ゝ 毕业季﹏ 提交于 2019-12-06 05:44:36
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 system myself. Many thanks, Sam go offline right after you got the page and then reload the web view.

Unit tests with NSURLSession

旧时模样 提交于 2019-12-06 02:47:32
问题 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 responses/data without requiring an internet connection. What is the less unobtrusive way of mocking these components? I was thinking of populating NSURLCache with mock responses and data but I feel this assumes too much of how NSURLSession and NSURLSessionDataTask work. Any other suggestions? 回答1: I've

NSURLCache crashes with autoreleased objects, but leaks otherwise

[亡魂溺海] 提交于 2019-12-06 02:23:52
问题 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 objects are simply leaked. Any light that could be shed onto this would be much appreciated. Please note stringByEncodingURLEntities is a category method on NSString . @interface CSURLCache : NSURLCache {} @end @implementation CSURLCache - (NSCachedURLResponse *)cachedResponseForRequest:(NSURLRequest *

Download and cache entire web page on ios

别说谁变了你拦得住时间么 提交于 2019-12-05 22:02:49
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 level libraries (NSURLConnection, NSCache) ASIHTTP doesn't get those advancements. Hence, I tried this

NSURLCache Memory Size is zero

随声附和 提交于 2019-12-05 12:31:32
I am having trouble caching NSURLConnection responses using a synchronous call. I initialize the cache in one class and then use it in another. Notice how the cache memory capacity gets initialized to 100KB but then is magically reset to zero later. - (id)init { if (self = [super init]) { // Creates a custom URL cache that uses both memory and disk. NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:kMemoryCacheSize * 1000000 diskCapacity:kDiskCacheSize * 1000000 diskPath:diskPath]; [NSURLCache setSharedURLCache:sharedCache]; NSLog(@"Cache memory capacity = %d bytes", [

NSURLCache - Disk caching for GET request with parameters not working

*爱你&永不变心* 提交于 2019-12-05 05:49:44
问题 I'm trying to cache some HTTP requests to disk using NSURLCache. After doing some tests with AFNetworking and not working, I created a simple example using NSURLRequest. I initialize the cache on the AppDelegate like this, setting the memory size to 0, forcing it to go always to Disk: NSUInteger sz = 1024*1024*20; NSURLCache *cache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:sz diskPath:nil]; [NSURLCache setSharedURLCache:cache]; I use the following code to store the response:

How to clear cache of app in objective C?

落爺英雄遲暮 提交于 2019-12-04 22:02:35
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 number.But it is not happening. The code i'm using to clear the app cache: - (void)viewDidLoad { [super viewDidLoad]; [[NSURLCache sharedURLCache] removeAllCachedResponses]; } Help is appreciated! Rather than go low-level and mess with NSURLCache, you can use your library's own high-level mechanics: [[Digits sharedInstance] logOut] Since some crucial

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

谁都会走 提交于 2019-12-04 20:27:54
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 webview will not be cached automatically. Does there any way to download the entire webpages? Thank you

iPhone: Performances Differences Between NSURLRequestCachePolicy Settings

二次信任 提交于 2019-12-04 18:09:43
问题 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 on the the user's perception of the speed at which UIWebView pages display. I have been using the default NSURLRequestCachePolicy but I think that perhaps NSURLRequestReloadRevalidatingCacheData could be best for most cases especially when going back to a previous page. If you've used various

Clear NSURLConnection cache

戏子无情 提交于 2019-12-04 15:18:48
问题 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. 回答1: You can clear the cache explicitly using: obj-c [[NSURLCache sharedURLCache] removeAllCachedResponses]; swift URLCache.shared.removeAllCachedResponses() 回答2: You specify cache policy when you create your NSURLRequest object. Set the cachePolicy property to NSURLRequestReloadIgnoringCacheData or use the initWithURL:cachePolicy