SDWebImage手动清除缓存的方法
1.找到SDImageCache类
2.添加如下方法:
- (float)checkTmpSize { float totalSize = 0; NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:diskCachePath]; for (NSString *fileName in fileEnumerator) { NSString *filePath = [diskCachePath stringByAppendingPathComponent:fileName]; NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil]; unsigned long long length = [attrs fileSize]; totalSize += length / 1024.0 / 1024.0; } // NSLog(@"tmp size is %.2f",totalSize); return totalSize; }
3.在设置里这样使用
#pragma 清理缓存图片 - (void)clearTmpPics { [[SDImageCache sharedImageCache] clearDisk]; // [[SDImageCache sharedImageCache] clearMemory];//可有可无 DLog(@"clear disk"); float tmpSize = [[SDImageCache sharedImageCache] checkTmpSize]; NSString *clearCacheName = tmpSize >= 1 ? [NSString stringWithFormat:@"清理缓存(%.2fM)",tmpSize] : [NSString stringWithFormat:@"清理缓存(%.2fK)",tmpSize * 1024]; [configDataArray replaceObjectAtIndex:2 withObject:clearCacheName]; [configTableView reloadData]; }
相关推荐
zhujiangtaotaise 2020-01-01
84407518 2012-07-16
AllenG 2013-07-07
Beatopcoder 2013-07-14
让编程改变世界 2015-03-13
shqhope 2015-04-09
zoutian00 2015-05-12
87214552 2015-10-27
84407518 2016-01-25
89283517 2012-06-19
ObjectiveC 2012-06-14
huangshm 2019-01-14
86981633 2019-06-29
我的iOS王者之路 2019-06-28
好好学习天天 2019-06-28
jscjxysx 2019-06-28