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开发--清理缓存


下一篇:iOS 清理缓存功能实现第一种方法