获取SDWebImage的缓存大小并清除

// 获取SDWebImage的缓存大小

- (NSString *)cacheSizeFormat
{
    NSString *sizeUnitString;
    float size = [SDWebImageManager.sharedManager.imageCache getSize];
    if(size < 1024){
        sizeUnitString = [NSString stringWithFormat:@"%.1fb",size];
        
    }else if (size > 1024 && size < 1024 * 1024) {
        size /= 1024.0;
        sizeUnitString = [NSString stringWithFormat:@"%.1fkb",size];
    }
    else{
        size /= (1024.0 * 1024);
        sizeUnitString = [NSString stringWithFormat:@"%.1fM",size];
    }
    return sizeUnitString;
}

 

//清除SDWebImage的缓存

else if ([selectText isEqualToString:@"清除缓存"]) {
   [[[SDWebImageManager sharedManager] imageCache] clearDisk];
   [[[SDWebImageManager sharedManager] imageCache] clearMemory];
   __weak typeof(self) weakSelf = self;
   dispatch_queue_t queue = dispatch_get_main_queue();
   dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), queue, ^{
       [MBProgressHUD showMessage:@"缓存清除成功"];
       [weakSelf reloadData];
   });
}

 

posted @ 2018-04-03 23:56  码出境界  阅读(399)  评论(0编辑  收藏  举报