清理缓存的几种方法
来源:互联网 发布:用友软件使用方法 编辑:程序博客网 时间:2024/04/29 08:57
在开发移动过程中, 清理缓存是最常见的一种功能, 接下来给大家介绍几种清理缓存的方法
第一种:
- (void)action:(id)sender{//彻底清除缓存第一种方法UIButton * button = sender;[button setTitle:@"清理完毕" forState:UIControlStateNormal];NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);NSString *path = [paths lastObject];NSString *str = [NSString stringWithFormat:@"缓存已清除%.1fM", [self folderSizeAtPath:path]];NSLog(@"%@",str);NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:path];for (NSString *p in files) {NSError *error;NSString *Path = [path stringByAppendingPathComponent:p];if ([[NSFileManager defaultManager] fileExistsAtPath:Path]) {[[NSFileManager defaultManager] removeItemAtPath:Path error:&error];}}
第二种:
基于第三方框架SDWebImage的清理缓存的方法
[[SDImageCache sharedImageCache] clearDisk];[[SDImageCache sharedImageCache] clearMemory];
第三种:
彻底清除缓存
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];NSLog(@"%@", cachPath);NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];NSLog(@"files :%d",[files count]);for (NSString *p in files) {NSError *error;NSString *path = [cachPath stringByAppendingPathComponent:p];if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {[[NSFileManager defaultManager] removeItemAtPath:path error:&error];}}[self performSelectorOnMainThread:@selector(clearCacheSuccess) withObject:nil waitUntilDone:YES];});}-(void)clearCacheSuccess{NSLog(@"清理成功");}
0 0
- IOS清理缓存的几种方法
- 清理缓存的几种方法
- myeclipse 清理项目缓存的几大方法
- MyEclipse 清理项目缓存的几大方法
- MyEclipse 清理项目缓存的几大方法
- MyEclipse 清理项目缓存的几大方法
- OpenGL清理缓存的两种方法
- mac磁盘清理的几种方法
- 清除(清理)MSSQL事务日志文件的几种方法
- 清理浮动的几种方法以及对应规范说明
- Mac下清理DNS缓存的方法
- linux下清理缓存的方法
- 页面缓存清理方法
- IE缓存清理方法
- 简介缓存清理方法
- iOS 清理缓存方法
- 清除几种缓存的方法
- 禁用页面缓存的几种方法
- mongodbTemplate查询
- 解决网页视频无法播放问题 (搜狐)
- 杂文
- openstack虚拟机问题处理一般流程
- Android动画_LayoutTransition
- 清理缓存的几种方法
- 浏览器插件框架
- POJ 1797 Heavy Transportation(最大生成树-Prim)
- 使用rsync同步数据(by quqi99)
- nginx 安装
- Address already in use: JVM_Bind:8080 解决办法
- Problem F: 冒泡排序法排序
- linux中通用GPIO接口的操作
- 微信"锐捷查询"的实现.md