使用SDWebImage清除图片缓存
2016-01-19 17:44
417 查看
使用下面清除缓存的方法需要导入#import "SDImageCache.h"
//清除缓存的点击方法
- (void)clearBtnClicked:(UIButton *)sender
{
NSString *caches = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
//调用清除方法
[self clearCache:caches];
}
//清除缓存文件
- (void)clearCache:(NSString *)path{
NSFileManager *fileManager=[NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:path]) {
NSArray *childerFiles=[fileManager subpathsAtPath:path];
for (NSString *fileName in childerFiles) {
//如有需要,加入条件,过滤掉不想删除的文件
NSString *absolutePath=[path stringByAppendingPathComponent:fileName];
[fileManager removeItemAtPath:absolutePath error:nil];
}
}
[[SDImageCache sharedImageCache] cleanDisk];
}
- (long long)fileSizeAtPath:(NSString *)filePath{
NSFileManager* manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:filePath]){
return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
}
return 0;
}
//遍历文件夹获得文件夹大小,返回多少M
- (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);
}
//清除缓存的点击方法
- (void)clearBtnClicked:(UIButton *)sender
{
NSString *caches = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
//调用清除方法
[self clearCache:caches];
}
//清除缓存文件
- (void)clearCache:(NSString *)path{
NSFileManager *fileManager=[NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:path]) {
NSArray *childerFiles=[fileManager subpathsAtPath:path];
for (NSString *fileName in childerFiles) {
//如有需要,加入条件,过滤掉不想删除的文件
NSString *absolutePath=[path stringByAppendingPathComponent:fileName];
[fileManager removeItemAtPath:absolutePath error:nil];
}
}
[[SDImageCache sharedImageCache] cleanDisk];
}
- (long long)fileSizeAtPath:(NSString *)filePath{
NSFileManager* manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:filePath]){
return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
}
return 0;
}
//遍历文件夹获得文件夹大小,返回多少M
- (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);
}
相关文章推荐
- hdu1874 畅通工程续
- 浅谈iOS中MVVM的架构设计与团队协作
- 2016
- 给 Android 开发者的 RxJava 详解
- android 调试多设备相同序列号问题
- Android图像处理之色彩特效处理(学习笔记)
- 【Storm入门指南】附录C 安装真实示例
- 将java web项目转为maven项目
- Android加壳原理分析
- 分布式消息系统:Kafka
- java执行效率低,但效率就低吗?
- Wireshark图解教程(简介、抓包、过滤器)
- 【Storm入门指南】附录B 安装Storm集群
- 从框架到完整项目搭建,实战项目《约个球》(4)-Intellij IDEA 导入library和jar文件
- redis常见操作命令-pub/sub
- FTP error : 451 Failure writing to local file
- 文顶顶博客园
- W3School-CSS 定位 (Positioning) 实例
- Ubuntu 完全卸载Apache2
- ShellExecute使用详解