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];}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。