1、获取缓存大小
- (CGFloat)getCachSize {
NSUIntegerimageCacheSize = [[SDImageCache sharedImageCache] getSize];
//获取自定义缓存大小//用枚举器遍历 一个文件夹的内容
//1.获取 文件夹枚举器
NSString*myCachePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"];NSDirectoryEnumerator*enumerator = [[NSFileManagerdefaultManager] enumeratorAtPath:myCachePath]; __blockNSUIntegercount =0;
//2.遍历
for(NSString*fileNameinenumerator) {NSString*path = [myCachePath stringByAppendingPathComponent:fileName];
NSDictionary*fileDict = [[NSFileManagerdefaultManager] attributesOfItemAtPath:path error:nil];
count += fileDict.fileSize;
//自定义所有缓存大小}
// 得到是字节 转化为
MCGFloattotalSize = ((CGFloat)imageCacheSize+count)/1024/1024;returntotalSize;
}
2、清除缓存
- (void)handleClearView {
//删除两部分//1.删除 sd 图片缓存
//先清除内存中的图片缓存
[[SDImageCache sharedImageCache] clearMemory];
//清除磁盘的缓存
[[SDImageCache sharedImageCache] clearDisk];
//2.删除自己缓存
NSString*myCachePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"];
[[NSFileManagerdefaultManager] removeItemAtPath:myCachePath error:nil];}