美文网首页
SDWebImage 清除图片缓存

SDWebImage 清除图片缓存

作者: 然亦伞 | 来源:发表于2016-09-14 17:56 被阅读27次

//获取缓存的大小

NSUInteger intg = [[SDImageCache sharedImageCache] getSize];

NSString *currentVolum = [NSString stringWithFormat:@"清理缓存%@",[self fileSizeWithInterge:intg]];

//清理缓存

[[SDImageCache sharedImageCache] clearMemory];//可有可无

[[SDImageCache sharedImageCache] clearDiskOnCompletion:^{

[MBProgressHUD showSuccess:currentVolum toView:self.view];

}];

//计算出大小

- (NSString *)fileSizeWithInterge:(NSInteger)size{

// 1k = 1024, 1m = 1024k

if (size < 1024) {// 小于1k

return [NSString stringWithFormat:@"%ldB",(long)size];

}else if (size < 1024 * 1024){// 小于1m

CGFloat aFloat = size/1024;

return [NSString stringWithFormat:@"%.0fK",aFloat];

}else if (size < 1024 * 1024 * 1024){// 小于1G

CGFloat aFloat = size/(1024 * 1024);

return [NSString stringWithFormat:@"%.1fM",aFloat];

}else{

CGFloat aFloat = size/(1024*1024*1024);

return [NSString stringWithFormat:@"%.1fG",aFloat];

}

}

相关文章

网友评论

      本文标题:SDWebImage 清除图片缓存

      本文链接:https://www.haomeiwen.com/subject/kqgvettx.html