APP中一般计算缓存大小 是通过SDWebImage计算的:
float tmpSize = [[SDImageCache sharedImageCache] getSize];
NSString *clearCacheName = tmpSize >= 1 ? [NSString stringWithFormat:@"%.1fMB",tmpSize/(1024*1024)] : [NSString stringWithFormat:@"%.1fKB",tmpSize * 1024];
self.clearCacheName = clearCacheName;
清理缓存
MBProgressHUD *hud = [[MBProgressHUD alloc] init];
[[[UIApplication sharedApplication].windows firstObject] addSubview:hud];
//加载条上显示文本
hud.labelText = @"急速清理中";
//置当前的view为灰度
hud.dimBackground = YES;
//设置对话框样式
hud.mode = MBProgressHUDModeDeterminate;
[hud showAnimated:YES whileExecutingBlock:^{
while (hud.progress < 1.0) {
hud.progress += 0.01;
[NSThread sleepForTimeInterval:0.02];
}
hud.labelText = @"清理完成";
} completionBlock:^{
[[SDImageCache sharedImageCache] clearDisk];
[[SDImageCache sharedImageCache] clearMemory];
block_self.clearCacheName = @"0.0KB";
[hud removeFromSuperview];
}];