ios 计算缓存大小并清理缓存
Posted 锦夏ing
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ios 计算缓存大小并清理缓存相关的知识,希望对你有一定的参考价值。
SDWebImage、WebView产生的缓存
1、计算缓存大小
//SDWebImage缓存大小
UILabel *cleanDetailText = [[UILabel alloc]init];
unsigned long iLength = [[SDImageCache sharedImageCache]getSize]/1024.0;
if(iLength > 1024.0)
{
iLength = iLength/1024.0;
NSString *sLength = [NSString stringWithFormat:@"%lu",iLength];
cleanDetailText.text = [sLength stringByAppendingString:@"M"];
}
else
{
NSString *sLength = [NSString stringWithFormat:@"%lu",iLength];
cleanDetailText.text = [sLength stringByAppendingString:@"kb"];
}
//WebView缓存大小
NSInteger sizeInteger = [[NSURLCache sharedURLCache] currentDiskUsage];
float sizeInMB = sizeInteger / (1024.0f * 1024.0f);
2、清理缓存
//SDWebImage清理缓存
[[[SDWebImageManager sharedManager]imageCache]clearDisk];
[[[SDWebImageManager sharedManager]imageCache]clearMemory];
//WebView清理缓存
[[NSURLCache sharedURLCache]removeAllCachedResponses];
以上是关于ios 计算缓存大小并清理缓存的主要内容,如果未能解决你的问题,请参考以下文章