three20图片缓存, image cache:
Date Cache:
UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 200, 200)];
[image setBackgroundColor:[UIColor redColor]];
// [self.view addSubview:image];
NSString *imgurl=@"http://img1.cache.netease.com/www/logo/logo-ipad-icon.png";
TTURLCache *cache = [TTURLCache sharedCache];
if (![cache hasDataForKey:imgurl expires:3000]) {
NSLog(@"缓存图片");
[[UIImage alloc]initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imgurl]]];
[cache storeImage:[[UIImage alloc]initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imgurl]]] forURL:imgurl];
}
//取缓存图片
if ([cache hasImageForURL:imgurl fromDisk:YES]) {
NSLog(@"取缓存图片");
[image setImage:[cache imageForURL:imgurl]];
}
[self.view addSubview:image];
Date Cache:
UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 200, 200)];
[image setBackgroundColor:[UIColor redColor]];
// [self.view addSubview:image];
NSString *imgurl=@"http://img1.cache.netease.com/www/logo/logo-ipad-icon.png";
TTURLCache *cache = [TTURLCache sharedCache];
NSLog(@"begin");
if (![cache hasDataForURL:imgurl]) {
NSLog(@"缓存图片");
[cache storeData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imgurl]] forURL:imgurl];
}
//取缓存图片
if ([cache hasDataForURL:imgurl]) {
NSLog(@"取缓存图片");
[image setImage:[UIImage imageWithData:[cache dataForURL:imgurl]]];
}
[self.view addSubview:image];
NSLog(@"end");