1. 计算图片缓存大小
- (void)imageCacheSize:(NSInteger) accuracy
{
dispatch_async(dispatch_get_global_queue(0, 0), ^{
CGFloat imageSize = ([[SDImageCache sharedImageCache] getSize] / 1024.0f) / 1024.0f;
NSString *imageSizeString = [NSString stringWithFormat:@"%f",imageSize];
NSRange dotRange = [imageSizeString rangeOfString:@"."];
NSInteger lastPosition = dotRange.location + accuracy;
imageSizeString = [imageSizeString substringToIndex:lastPosition];
dispatch_async(dispatch_get_main_queue(), ^{
self.cacheLabel.text = [NSString stringWithFormat:@"%@ M",imageSizeString];
});
});
}
2. 清除缓存
- (void)goToClearCache
{
[NSThread detachNewThreadSelector:@selector(clearCache) toTarget:self withObject:nil];
//loading
[self performSelector:@selector(clearCacheFinished) withObject:nil afterDelay:1];
}
- (void)clearCache
{
[[SDImageCache sharedImageCache] clearDisk];
[[SDImageCache sharedImageCache] clearMemory];
}
- (void)clearCacheFinished
{
//清除成功
//缓存大小清空
self.cacheLabel.text = @"0 M";
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。