NSURLRequest Caching Policy

I am using NSURLRequest with CachePolicy to load plist in NSData. When I modify the contents of my plist, my application ignores this and still presents the contents that are cached. How long does the cache last? If so, is it possible to say how long the cache data is stored? Is there a way to check NSURLRequest if the data on the server is newer than the cache, download data from the server or, if it is equal to the cache, use the cache?

+5
source share
1 answer

Take a look at Managing Response Caching in URLLoadingSystem Documents .

You can add your own date to delegate methods.

-(NSCachedURLResponse *)connection:(NSURLConnection *)connection
                 willCacheResponse:(NSCachedURLResponse *)cachedResponse

ASIHTTPRequest. URL.

apple:

6 https. .

-(NSCachedURLResponse *)connection:(NSURLConnection *)connection
                 willCacheResponse:(NSCachedURLResponse *)cachedResponse
{
    NSCachedURLResponse *newCachedResponse = cachedResponse;

    if ([[[[cachedResponse response] URL] scheme] isEqual:@"https"]) {
        newCachedResponse = nil;
    } else {
        NSDictionary *newUserInfo;
        newUserInfo = [NSDictionary dictionaryWithObject:[NSCalendarDate date]
                                                 forKey:@"Cached Date"];
        newCachedResponse = [[[NSCachedURLResponse alloc]
                                initWithResponse:[cachedResponse response]
                                    data:[cachedResponse data]
                                    userInfo:newUserInfo
                                    storagePolicy:[cachedResponse storagePolicy]]
                            autorelease];
    }
    return newCachedResponse;
}
+2

All Articles