天天看点

ios清除缓存的两种有效方法

利用第三方框架SDWebImage

  1. 获知缓存大小

    [SDImageCache SharedImageCache].getsize

  2. 清除缓存

    [[SDImageCache SharedImageCache] clearDisk]

利用文件管理

创建文件管理者

[NSFileManager defaultManager]

获取路径

[mgr attributesOfItemAtPath:cachePath error:nil]

遍历caches一个文件夹里面内容 ——直接内容

[mgr contentsOfDirectoryAtPath:caches error:nil]

获取caches文件夹及子文件的下面的所有内容路径—-直接和间接的都有

[mgr subpathAtPath:caches];

判断是否为文件

[mgr fileExistsAtPath:fullpath isDirectory:&dir];

删除文件

[mgr removeItemAtPath:caches error:nil];

iOS