清除缓存数据的方法
来源:互联网 发布:linux下启动tomcat 编辑:程序博客网 时间:2024/05/16 06:28
我们在做项目的时候,常常需要一个清除数据缓存的功能,下面的一些代码是我平常用的清除缓存的方法
#import "UIImageView+WebCache.h"#import "SDImageCache.h"//包含头文件 借助于SDWebImage库//创建一个buttonUIButton *DelButton=[UIButton buttonWithType:UIButtonTypeCustom]; DelButton.frame=CGRectMake(40, 100, 60, 40); [DelButton addTarget:self action:@selector(DelButton) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:DelButton];
-(void)DelButton{UIActionSheet *sheet=[[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:@"删除缓存文件:%.2fM",[self getCachesSize]] delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"删除" otherButtonTitles:nil]; [sheet showInView:self.view];}
-(double)getCachesSize{ //获取缓存数据 double sdSize=[[SDImageCache sharedImageCache] getSize]; NSString *myCachePath=[NSHomeDirectory() stringByAppendingFormat:@"/Library/Caches/MyCaches"]; NSDirectoryEnumerator *enumerator=[[NSFileManager defaultManager] enumeratorAtPath:myCachePath]; double mySize=0; for (NSString *fileName in enumerator) { NSString *filePath=[myCachePath stringByAppendingPathComponent:fileName]; NSDictionary *dict=[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil]; mySize +=dict.fileSize; } double totalSize=sdSize/1024/1024;//转化为M return totalSize;}-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{//清除缓存 if (buttonIndex==actionSheet.destructiveButtonIndex) { [[SDImageCache sharedImageCache] clearMemory]; [[SDImageCache sharedImageCache] clearDisk]; NSString *myCachePath=[NSHomeDirectory() stringByAppendingFormat:@"/Library/Caches/MyCaches"]; [[NSFileManager defaultManager] removeItemAtPath:myCachePath error:nil]; }}
0 0
- 清除缓存数据的方法
- ShowModalDialog数据缓存的清除方法
- ShowModalDialog数据缓存的清除方法
- 清除缓存的方法
- php 清除缓存的方法
- response方法清除缓存的
- 清除ajax缓存的方法
- varnish清除缓存的方法
- 清除ARP缓存的方法
- 清除DNS缓存的方法
- iOS清除缓存的方法
- C#清除缓存、清除IE临时文件缓存cookies的方法
- 清除火狐浏览器的缓存数据
- 低调的转载,清除缓存数据
- app缓存数据的大小和清除
- 清除项目中缓存的数据
- Android清除数据、清除缓存、一键清理的区别
- 简单的清除IE缓存的方法
- PHP设计模式——封装Mysql数据库
- iOS开发 UI UICollectionView 瀑布流
- 一个纯js的ajax
- windows7 IIS 怎么绑定固定IP和域名
- ORALE11G数据导入ORACLE9i方法
- 清除缓存数据的方法
- Android中按钮的点击事件监听
- Pro Git(中文版)
- 计算两个经纬度之间的距离
- CentOS安装jdk
- Java日志框架slf4j、jcl、jul、log4j1、log4j2、logback大总结
- Object-C中编写省略参数的多参数函数
- Yii1.1中的关联查询
- Textview内容过多,尾部显示省略号或【更多】