-(void)downloadDataForURL:(NSURL *)url{ NSPurgeableData *cachedData = [_cache objectForKey:url]; // 实现NSDiscardableContent协议的对象 if(cachedData){ //Stop the data being purged [cachedData beginContentAccess]; //Use the cached data [self useData:cachedData]; //Mark that the data may be purged again [cachedData endContentAccess]; }else{ //Cache miss EOCNetworkFetcher *fetcher = [[EOCNetworkFetcher alloc]initWithURL:url]; [fetcher startWithCompletionHandler:^(NSData *data) { NSPurgeableData *purgeableData = [NSPurgeableData dataWithData:data]; [_cache setObject:purgeableData forKey:url cost:data.length]; //Don't need to beginContentAccess as it begins //with access already marked //Use the retrieved data [self useData:data]; //Mark that the data may be purged now [purgeableData endContentAccess]; }]; } }