使用SDWebImage 清除App 缓存
2016-01-22 11:35
309 查看
首先在tableView上面加载图片缓存大小
{
NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSString *floderPath = [cachesPath stringByAppendingPathComponent:@"com.hackemist.SDWebImageCache.default"];
NSLog(@"cachesPath --> %@", floderPath);
float floderSize = [self folderSizeAtPath:floderPath];
NSLog(@"floderSize : %f", floderSize);
//加载缓存到UI界面即可!!!
}
#pragma mark 清理缓存
- (void)clearTmpPics
{
[[SDImageCache sharedImageCache] clearDisk];
[[SDImageCache sharedImageCache] clearMemory];//可有可无
NSLog(@"clear disk");
float tmpSize = [[SDImageCache sharedImageCache] getSize];
NSString *clearCacheName = tmpSize >= 1 ? [NSString stringWithFormat:@"清理缓存(%.2fM)",tmpSize] : [NSString stringWithFormat:@"清理缓存(%.2fK)",tmpSize * 1024];
NSLog(@"%@", clearCacheName);
}
// 缓存中单个文件大小
- (long long) fileSizeAtPath:(NSString*) filePath{
NSFileManager* manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:filePath]){
return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
}
return 0;
}
// 全部文件大小
- (float)folderSizeAtPath:(NSString*) folderPath{
NSFileManager* manager = [NSFileManager defaultManager];
if (![manager fileExistsAtPath:folderPath])
return 0;
NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
NSString* fileName;
long long folderSize = 0;
while ((fileName = [childFilesEnumerator nextObject]) != nil){
NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
folderSize += [self fileSizeAtPath:fileAbsolutePath];
}
return folderSize/(1024.0*1024.0);
}
使用SDWebImage 清除App本地缓存 还是比较简单的 希望以后如果遇到相似的问题
可以和各位大神一起探讨!!!
{
NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSString *floderPath = [cachesPath stringByAppendingPathComponent:@"com.hackemist.SDWebImageCache.default"];
NSLog(@"cachesPath --> %@", floderPath);
float floderSize = [self folderSizeAtPath:floderPath];
NSLog(@"floderSize : %f", floderSize);
//加载缓存到UI界面即可!!!
}
#pragma mark 清理缓存
- (void)clearTmpPics
{
[[SDImageCache sharedImageCache] clearDisk];
[[SDImageCache sharedImageCache] clearMemory];//可有可无
NSLog(@"clear disk");
float tmpSize = [[SDImageCache sharedImageCache] getSize];
NSString *clearCacheName = tmpSize >= 1 ? [NSString stringWithFormat:@"清理缓存(%.2fM)",tmpSize] : [NSString stringWithFormat:@"清理缓存(%.2fK)",tmpSize * 1024];
NSLog(@"%@", clearCacheName);
}
// 缓存中单个文件大小
- (long long) fileSizeAtPath:(NSString*) filePath{
NSFileManager* manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:filePath]){
return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
}
return 0;
}
// 全部文件大小
- (float)folderSizeAtPath:(NSString*) folderPath{
NSFileManager* manager = [NSFileManager defaultManager];
if (![manager fileExistsAtPath:folderPath])
return 0;
NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
NSString* fileName;
long long folderSize = 0;
while ((fileName = [childFilesEnumerator nextObject]) != nil){
NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
folderSize += [self fileSizeAtPath:fileAbsolutePath];
}
return folderSize/(1024.0*1024.0);
}
使用SDWebImage 清除App本地缓存 还是比较简单的 希望以后如果遇到相似的问题
可以和各位大神一起探讨!!!
相关文章推荐
- iOS 数组遍历删除元素的问题
- iOS程序猿之本地通知那些事
- 解决Android自定义CheckBox图片过大的问题
- cocos studio的帧事件
- 仿微信查看系统图片缩略图选择多张图片
- Android Studio 版本控制要忽略的文件
- iOS 关于presentViewController弹出页面反应迟钝的问题
- Android学习历程9-Android事件处理
- Android开发中,有哪些让你觉得相见恨晚的方法、类或接口?
- android之回调函数的用法和意义
- ios 移动端架构浅析
- Android APP 增量更新demo
- APK瘦身方案
- Android Studio查看SVN历史记录不能正确显示中文
- IOS图片压缩(修改图片大小)
- Android自定义View-绘制扇形实现圆形进度
- iOS开发常用的第三方资源
- android XML file之ClipDrawable
- Android视觉规范-间距规范与文字规范单位换算(dip、sp与px)
- 友盟分享到微信的几点备忘(IOS)