显示缓存值:
UILabel *cacheLabel = [[UILabel alloc] initWithFrame:CGRectMake(JKScreenW - 140, 0, 100, 40)];
[cell addSubview:cacheLabel];
cacheLabel.font = [UIFont jk_systemFontOfPxSize:28];
cacheLabel.textColor = JKSameRGBColor(153);
cacheLabel.textAlignment = NSTextAlignmentRight;
NSUInteger intg = [[SDImageCache sharedImageCache] getSize];
NSString *currentVolum = [NSString stringWithFormat:@"%@",[self fileSizeStringWithInterge:intg]];
cacheLabel.text = currentVolum;
_cacheLabel = cacheLabel;
- (NSString *)fileSizeStringWithInterge:(NSInteger)size{
if (size < 1024) {
return [NSString stringWithFormat:@"%ldB",(long)size];
}else if (size < 1024 * 1024){
CGFloat aFloat = size/1024;
return [NSString stringWithFormat:@"%.0fK",aFloat];
}else if (size < 1024 * 1024 * 1024){
CGFloat aFloat = size/(1024 * 1024);
return [NSString stringWithFormat:@"%.1fM",aFloat];
}else{
CGFloat aFloat = size/(1024*1024*1024);
return [NSString stringWithFormat:@"%.1fG",aFloat];
}
}
清除缓存:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"是否清除缓存" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[SDImageCache sharedImageCache] clearDiskOnCompletion:nil];
[[SDImageCache sharedImageCache] clearMemory];
[JKProgressHUD showSuccessWithStatus:@"清除缓存成功!"];
_cacheLabel.text = @"";
}];
[alertController addAction:cancelAction];
[alertController addAction:sureAction];
[self presentViewController:alertController animated:NO completion:nil];