APP中的清除缓存

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];
    }];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容