sdwebimage如何获取缓存大小以及清除缓存
2015-09-23 16:31
603 查看
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];
}
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];
}
相关文章推荐
- 【数位DP】Hdu 2089:不要62
- java assert的使用并深入解析Java的assertion
- SharePoint自动化系列——通过PowerShell创建SharePoint List Items
- Linux网络配置命令
- 面试---(x&y) + ( (x^y)>>1 )求平均数
- DWZ实现排序
- jQuery 中.parent() .parents() .parentsUntil()的区别,一看就懂。
- Android studio创建模拟器报错
- Unity3D中uGUI事件系统简述及使用方法总结
- Java学习笔记【数组知识要点】
- UITableViewCell unable to dequeue a cell with identifier Cell - must register a nib or a class for t
- CentOS 7 启动VNC失败问题
- thinkphp框架使用支付宝
- Zabbix 集成 OneAlert 实现全方位告警
- executing preg_match_all() function with this Regular Expression causes a PHP Segmentation Fault.
- nasm : 屏幕打印语句的实现
- Java EE : 一、图解Http协议
- systemd系统服务管理详解
- mesos和Elasticsearch设计(一)
- 微信和百度地图都不支持iOS6了