清除缓存
2015-11-23 14:15
253 查看
1.图片缓存 (SDWebImage)
// - 计算缓存大小
int byteSize = [SDImageCachesharedImageCache].getSize;
// M大小
double size = byteSize /
1000.0 / 1000.0;// - 缓存的大小(M)
// - 清除缓存
[[SDImageCachesharedImageCache]
clearDisk];
2.其他的缓存
// - 计算缓存大小
NSLog(@"%d", [@"/Users/apple/Desktop/ios就业指导"
fileSize]);
// - 清除缓存
NSFileManager *mgr = [NSFileManagerdefaultManager];
//
缓存路径
NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,
YES)lastObject];
[mgr removeItemAtPath:cacheserror:nil];
- (NSInteger)fileSize
{
NSFileManager *mgr = [NSFileManagerdefaultManager];
//
判断是否为文件
BOOL dir = NO;
BOOL exists = [mgr
fileExistsAtPath:self
isDirectory:&dir];
//
文件\文件夹不存在
if (exists ==
NO) return
0;
if (dir) { // self是一个文件夹
//
遍历caches里面的所有内容 ---直接和间接内容
NSArray *subpaths = [mgr
subpathsAtPath:self];
NSInteger totalByteSize =
0;
for (NSString *subpathin subpaths) {
// 获得全路径
NSString *fullSubpath = [selfstringByAppendingPathComponent:subpath];
// 判断是否为文件
BOOL dir =
NO;
[mgr fileExistsAtPath:fullSubpath
isDirectory:&dir];
if (dir ==
NO) { // 文件
totalByteSize += [[mgr attributesOfItemAtPath:fullSubpatherror:nil][NSFileSize]integerValue];
}
}
return totalByteSize;
} else {// self是一个文件
return [[mgrattributesOfItemAtPath:selferror:nil][NSFileSize]integerValue];
}
}
// - 计算缓存大小
int byteSize = [SDImageCachesharedImageCache].getSize;
// M大小
double size = byteSize /
1000.0 / 1000.0;// - 缓存的大小(M)
// - 清除缓存
[[SDImageCachesharedImageCache]
clearDisk];
2.其他的缓存
// - 计算缓存大小
NSLog(@"%d", [@"/Users/apple/Desktop/ios就业指导"
fileSize]);
// - 清除缓存
NSFileManager *mgr = [NSFileManagerdefaultManager];
//
缓存路径
NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,
YES)lastObject];
[mgr removeItemAtPath:cacheserror:nil];
- (NSInteger)fileSize
{
NSFileManager *mgr = [NSFileManagerdefaultManager];
//
判断是否为文件
BOOL dir = NO;
BOOL exists = [mgr
fileExistsAtPath:self
isDirectory:&dir];
//
文件\文件夹不存在
if (exists ==
NO) return
0;
if (dir) { // self是一个文件夹
//
遍历caches里面的所有内容 ---直接和间接内容
NSArray *subpaths = [mgr
subpathsAtPath:self];
NSInteger totalByteSize =
0;
for (NSString *subpathin subpaths) {
// 获得全路径
NSString *fullSubpath = [selfstringByAppendingPathComponent:subpath];
// 判断是否为文件
BOOL dir =
NO;
[mgr fileExistsAtPath:fullSubpath
isDirectory:&dir];
if (dir ==
NO) { // 文件
totalByteSize += [[mgr attributesOfItemAtPath:fullSubpatherror:nil][NSFileSize]integerValue];
}
}
return totalByteSize;
} else {// self是一个文件
return [[mgrattributesOfItemAtPath:selferror:nil][NSFileSize]integerValue];
}
}
相关文章推荐
- IOS7原生API进行二维码条形码的扫描
- Hibernate框架学习(二)
- QT pro工程文件的格式
- getView缓存的处理
- ios蓝牙开发(四)BabyBluetooth蓝牙库
- Linux压缩与归档
- first bit
- 1002. 写出这个数 (20)
- Java操作ini文件
- Hibernate框架学习(一 )
- 微信
- 遗传算法入门到掌握(二)
- 14.2.6.4 Physical Structure of an InnoDB Index InnoDB Index 物理结构
- iOS9 beta 请求出现App Transport Security has blocked a cleartext HTTP (http://)
- 053-5 You run the SQL Tuning Advisor (STA) to tune a SQL statement that is part of a fixed SQL plan
- ios蓝牙开发(三)app作为外设被连接的实现
- Java - 常用类
- redis cluster 集群 安装 配置 详解
- 是什么原因导致 无法连接到远程服务器
- iBatis框架使用 编程4步