Reputation: 4789
I have a little confusion in understanding the caching mechanism in iOS.
I have been reading this blog on NSURLCache to customize my caching policy. I want my caching to be completely controlled by my server caching headers.
So I set
[request setCachePolicy:NSURLRequestReturnCacheDataElseLoad];
Now the above blog specifies that I can also specify cache policy for NSCachedURLResponse.
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection
willCacheResponse:(NSCachedURLResponse *)cachedResponse
{
NSMutableDictionary *mutableUserInfo = [[cachedResponse userInfo] mutableCopy];
NSMutableData *mutableData = [[cachedResponse data] mutableCopy];
NSURLCacheStoragePolicy storagePolicy = NSURLCacheStorageAllowedInMemoryOnly;
// ...
return [[NSCachedURLResponse alloc] initWithResponse:[cachedResponse response]
data:mutableData
userInfo:mutableUserInfo
storagePolicy:storagePolicy];
}
Then whats the use of having a cache policy for the request in first place ? Is storage policy a request parameter or response parameter.
Upvotes: 1
Views: 792
Reputation: 13302
The difference is here:
NSURLRequestCachePolicy
is client-server data management feature that describes sources of data that should be loaded (local cache or remote server) and conditions between them.
NSURLCacheStoragePolicy
is only client data management feature that describes storage for local cache (memory, local database and etc; only memory; none).
For example if you use NSURLRequestReturnCacheDataElseLoad
for request and NSURLCacheStorageAllowedInMemoryOnly
for response then such scenario takes place:
Upvotes: 3