pre-knowledge recognition :
HTTP protocols from last-modified and etag with , detailed . simple to that is, , server service Returns A Resource contains an ID ( time or a token ), customer User end cache this I D, the next request is the same resource time , including This ID, server server determines resource whether to change change to return different result (200, or 304 ).
Three20The default cache solution is as follows:
Tturlrequestcachepolicydefault
= (Tturlrequestcachepolicymemory | tturlrequestcachepolicydisk
| Tturlrequestcachepolicynetwork ),
Tturlrequestcachepolicynetwork indicates that the last-modified policy is used,
Tturlrequestcachepolicymemory | tturlrequestcachepolicydisk indicates that memory and files are used.Cache ResourcesAndResource ID,
ChangeChange cache solution:
Tturlrequest request;
// Blah, blah
Request. cachepolicy = cachepolicy | tturlrequestcachepolicyetag;
HereAdded the etag function.ServicesSupportedWords, No doubtAsk thisThe best solution. And so on.Cache.
How to UseCache:
HerePull a ttimageview generationCodeAt first glance, you will know:
-(Void) Reload {
If(Nil=_ Request&&Nil! =_ Urlpath){
Uiimage*Image= [[Tturlcache Sharedcache]Imageforurl:_ Urlpath];
If(Nil! =Image){
Self.Image=Image;
}Else{
Tturlrequest* Request = [Tturlrequest Requestwithurl:_ Urlpath Delegate:Self];
Request.Response= [[[Tturlimageresponse Alloc]Init]Autorelease];
If(! [RequestSend]) {
// Put the default image in place while waiting for the request to load
If(_ Defaultimage&&Nil=Self.Image){
Self.Image=_ Defaultimage;
}
}
}
}
}
UseTturlcacheOfSingleFor example,YesObtainArbitrary URLResourcesLocalCache.HereOfLogicYesThis wayOf:
First, determine whether the memory existsThis image:
Uiimage*Image= [[Tturlcache Sharedcache]Imageforurl:_ Urlpath]
If not,InitiateOne request, usingRecognizePolicy,Obtain the image. Assume that the image was last openedProgramHas been downloaded, has been cached in disk (this is the default), and the image is not changed on the server, and the server supports if-modified, the request will return the image on disk by default.
DetailsYou can see tturlcache
Summary:
IfSendOne request,ThenMoRecognizeThe policy can be very good.Implemented CacheMechanism. Some built-in controls, such as tttableviewImage, AlsoImplementationIs ideal.