清除图片缓存

来源:互联网 发布:蚊子为什么要吸血知乎 编辑:程序博客网 时间:2024/05/22 22:17

- (void)setupGroup1

{

    // 1.创建组

    LKCommonGroup *group = [LKCommonGroup group];

    [self.groups addObject:group];

    

    // 2.设置组的所有行数据

     LKCommonArrowItem *clearCache = [LKCommonArrowItem itemWithTitle:@"清除图片缓存"];

    

    // 设置缓存的大小

//    NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];

//    [caches stringByAppendingPathComponent:@"com.hackemist.SDWebImageCache.default"];

    NSString *imageCachePath = [SDImageCache sharedImageCache].diskCachePath;

    long long fileSize = [imageCachePath fileSize];

    

    clearCache.subtitle = [NSString stringWithFormat:@"(%.1fM)", fileSize / (1000.0 * 1000.0)];

    

    __weak typeof(clearCache) weakClearCache = clearCache;

    __weak typeof(self) weakVc = self;

    clearCache.operation = ^{

        [MBProgressHUD showMessage:@"正在清除缓存...."];

        

        // 清除缓存

        NSFileManager *mgr = [NSFileManager defaultManager];

        [mgr removeItemAtPath:imageCachePath error:nil];

        

        // 设置subtitle

        weakClearCache.subtitle = nil;

        

        // 刷新表格

        [weakVc.tableView reloadData];

        

        [MBProgressHUD hideHUD];

    };

    

    group.items = @[clearCache];

    

//    LKLog(@"%lld", [@"/Users/apple/Desktop/音乐" fileSize]);

}


0 0