iOS 清除缓存(笔记)

float tmpSize = [[SDImageCache sharedImageCache] getSize];

NSString *clearMessage = tmpSize >= 1024 * 1024 ? [NSString stringWithFormat:@"清理缓存(%.2fM)" , tmpSize / 1024 / 1024] : [NSString stringWithFormat:@"清理缓存(%.2fK)", tmpSize / 1024];


UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:clearMessage preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

}];


UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

[[SDImageCache sharedImageCache]clearDisk];

//清除内存缓存

[[[SDWebImageManager sharedManager] imageCache] clearMemory];

//清除系统缓存

[[NSURLCache sharedURLCache] removeAllCachedResponses];

}];


[alert addAction:action2];

[alert addAction:action1];

[self presentViewController:alert animated:YES completion:nil];

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

推荐阅读更多精彩内容