清除SDImageCache的缓存


- (void)showInfo
{
    NSDirectoryEnumerator *fileEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:diskCachePath];
    int i = 0;
    float total = 0.0f;
    NSNumberFormatter *numberFormatter =[[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat: @"#,##0.## bytes"];
    for (NSString *fileName in fileEnumerator){
        NSLog(@"filename %d  :  %@", i, fileName);
        NSString *filePath = [diskCachePath stringByAppendingPathComponent:fileName];
        NSDictionary *attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
        if (attrs) {
            //获取文件的字节大小
            NSNumber *fileSize = (NSNumber*)[attrs objectForKey: NSFileSize];
            total = [fileSize floatValue] + total;
            //格式化文件大小
            NSString *A = [numberFormatter stringFromNumber: fileSize];
            NSLog(@"filesize %d  :  %@", i, A);
        }
        ++i;
    }
    NSLog(@"%f bytes (%f M) in cache", total, total / 1024.0 / 1024.0);
    [numberFormatter release];
}


SDImageCache *cache = [SDImageCachesharedImageCache];

            NSLog(@"cache 位置: %@", [cache getDiskCachePath]);

            [cache clearDisk];

            [cache clearMemory];

 

你可能感兴趣的:(Objective-C,SDImageCache)