码迷,mamicode.com
首页 > 移动开发 > 详细

ios 计算缓存大小并清理缓存

时间:2016-03-24 16:27:10      阅读:388      评论:0      收藏:0      [点我收藏+]

标签:

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 计算缓存大小并清理缓存

标签:

原文地址:http://www.cnblogs.com/huaixu/p/5315690.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!