nsurlcache

NSURLCache Problem with cache response

耗尽温柔 提交于 2019-12-04 14:09:50
问题 I'm writing an iPhone application, one of it's tabs is a twitter feed, i'm parsing twitter xml and putting it nicely inside a table view. In case there is no internet connection I would like to show cache results of the last time we had internet connection and the tables were updated. I'm using NSURLCache for that like so: NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:xmlLink] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60]; NSURLCache

Unit tests with NSURLSession

。_饼干妹妹 提交于 2019-12-04 09:02:39
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? I've used OHHTTPStubs to mock responses lately. You just register the stub before you test (example from the

Is NSURLCache persistent across launches?

倖福魔咒の 提交于 2019-12-04 08:59:34
问题 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 know how this behaves when you use NSURLCache then close and open the app? Does it persist? 回答1: NSURLCache automatically caches requests for requests made over NSURLConnection and UIWebView s according to the cache response from the server, the cache configuration, and the request's cache policy

NSURLCache crashes with autoreleased objects, but leaks otherwise

余生长醉 提交于 2019-12-04 08:58:58
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 *)request { NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask,

NSURLCache - Disk caching for GET request with parameters not working

微笑、不失礼 提交于 2019-12-03 20:08:34
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: NSURLCache *urlCache = [NSURLCache sharedURLCache]; NSString *urlString = @"http://localhost:8000

clearing a webviews cache for local files

守給你的承諾、 提交于 2019-12-03 12:46:55
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 file. The user should rarely ever look at this document, and my app is tight on memory, so what I want to do is prevent the UIWebView from caching the document. Another viable option is to clear the cache when the user leaves the view. I'm totally ok with having to load it from scratch every time the user enters the view. I load the document like so: NSString * path = [[NSBundle mainBundle]

iPhone: Performances Differences Between NSURLRequestCachePolicy Settings

ぐ巨炮叔叔 提交于 2019-12-03 12:27:25
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 cache policies under real-world conditions, which policy proved optimum in a particular circumstance? What

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

☆樱花仙子☆ 提交于 2019-12-03 09:14:18
问题 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 make within an iOS App. When the device is online, I'd like to return the cached response if it's recent enough, otherwise fetch from remote. When the device is offline I'd like to immediately return the cached response (if any) regardless of it's age. I'm using AFNetworking . The API calls that I

Transition from RestKit to pure AFNetworking 2.0

爱⌒轻易说出口 提交于 2019-12-03 06:47:50
问题 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: There is big need in using NSURLSession for background fetches and RestKit has only experimental branch for transition to AFNetworking 2.0. No actual dates when transition will be finished. (Main Reason) No need for CoreData support in network library as no need for fully functional offline data

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

时光总嘲笑我的痴心妄想 提交于 2019-12-02 23:19:56
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 make within an iOS App. When the device is online, I'd like to return the cached response if it's recent enough, otherwise fetch from remote. When the device is offline I'd like to immediately return the cached response (if any) regardless of it's age. I'm using AFNetworking . The API calls that I'm making are to a server I control. Protocol is HTTPS. The Cache-Control response header is currently