ios - NSURLCacheStoragePolicy request vs response -
There is little confusion in understanding the caching mechanism in the iOS. I
I want to customize my caching policy I am reading this blog. I want my caching to be completely controlled by my server caching header
so I set
[request set policy: NSURLRequestReturnCacheDataElseLoad];
The above mentioned blog now specifies that I can also specify a cash policy for NSCachedURLResponse. (NSCachedURLResponse *) Connection: (NSURLConnection *) connection will be CacheResponse: (NSCachedURLResponse *) Cached Response {NSMutableDictionary * mutableUserInfo = [[Cached Response User Infoda] MuteCopy]; NSMutableData * mutableData = [[Cached Response Data] MuteCopy]; NSURLCacheStoragePolicy storagePolicy = NSURLCacheStorageAllowedInMemoryOnly; // ... return [[NSCachedURLResponse alloc] initWithResponse: [Cached Response Response] Data: Migration Data User Information: mutableUserInfo storage policy: storage policy]; }
Then what is the meaning of having a cash policy for the first time? Storage policy is a request parameter or response parameter.
The difference is here:
NSURLRequestCachePolicy
is client-server data management The feature that loads sources of data (that is, local cache or remote server ) and describes situations between them
NSURLCacheStoragePolicy
is the only client data management utility that describes storage for local cache (memory, local database and etc; only memory; none). TI.
For example, if you use the NSURLRequestReturnCacheDataElseLoad
for the request and for response NSURLCacheStorageAllowedInMemoryOnly
is such a scenario:
- You initiate the request;
- The NSURL loads the connection connection to the server because it requests the first time and there is no cache;
- When the response is received, it is saved in cash storage on the cash memory (this will be live only when your application is launched;
- ;
- Loads the NSRR connection connection from local cache storage;
- You close the application (cache storage has been released), launch it again and launch a Only start the request;
- NSURLConnection of the load data from the server The form was released cache storage based on memory.
Comments
Post a Comment