现在的位置: 首页 > 综合 > 正文

asi缓存实例

2013年10月05日 ⁄ 综合 ⁄ 共 977字 ⁄ 字号 评论关闭

    if (self) {

        // Custom initialization

        //初始化ASIDownloadCache缓存对象

        ASIDownloadCache *cache = [[ASIDownloadCache
alloc] init];    

        self.downloadCache = cache;    

        [cache release];

        //路径    

        NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,
YES);

        NSString *documentDirectory = [paths
objectAtIndex:0];

        //设置缓存存放路径

        [self.downloadCache
setStoragePath:[documentDirectory stringByAppendingPathComponent:@"resource"]];

        //    [self.downloadCache setDefaultCachePolicy:ASIAskServerIfModifiedWhenStaleCachePolicy];

        [[ASIDownloadCache
sharedCache]setShouldRespectCacheControlHeaders:NO];

        

        NSURL *url = [NSURL
URLWithString:CMBURLString(kCityListAPI)];

        ASIHTTPRequest *request = [ASIHTTPRequest
requestWithURL:url];

        [request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy ];

        [request setDownloadCache:downloadCache];

        [request setSecondsToCache:60*60*24*7];
//缓存7

        [request setDelegate:self];

        [request startAsynchronous]; 

    }

抱歉!评论已关闭.