zoukankan      html  css  js  c++  java
  • iOS中清除缓存的方法 以及SDWebimage自带的清除缓存方法

    1  SDWebimage中 

    (1)  计算缓存的大小 

    单位 : (MB)

      CGFloat size = [[SDImageCache sharedImageCache] getSize] / 1024 / 1024.;

    (2)  清除缓存

    给button设置一个点击事件, 弹出警告框

     UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"清理缓存" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];

    (3) 使用UIAlertView的回调方法判断点击的下标惊醒下一步操作

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
        if (buttonIndex == 0) {
            [[SDImageCache sharedImageCache] clearDisk];
            [self.tableView reloadData];
    }

    / /    自己实现清除缓存

    - (void)cleanCase
    {
        [self startAnimation];
        //创建文件夹
        NSFileManager *fileManager = [NSFileManager defaultManager];
        //缓存
        NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
        //判断是否存在一个文件或者文件夹
        BOOL flag = NO;
        BOOL result = [fileManager fileExistsAtPath:cachesPath isDirectory:&flag];
        if (result) {
            NSLog(@"存在");
            if (flag) {
                NSLog(@"是一个文件夹");
                NSError *error = nil;
                BOOL removeResult =[fileManager removeItemAtPath:cachesPath error:&error];
                if (removeResult) {
                    NSLog(@"删除成功");
                    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"恭喜您" message:@"清除缓存成功" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                    [alertView show];
                    [alertView release];
                }
            } else {
                NSLog(@"是一个文件");
            }
        } else {
            NSLog(@"不存在");
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"没有可清理的缓存了哦!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alertView show];
            [alertView release];
        }

  • 相关阅读:
    博客的开端,找对象不再new
    OpenGL编程 基础篇(六)OpenGL中几种光照参数
    OpenGL编程 基础篇(五)世界窗口和视口
    百练2952:循环数
    百练2811:熄灯问题
    百练2812:恼人的青蛙
    百练3177:判决素数个数
    百练1248:Safecracker
    OpenGL编程 基础篇(四)与鼠标的交互
    OpenGL编程 基础篇(三)用点集绘制函数
  • 原文地址:https://www.cnblogs.com/tian-sun/p/4351427.html
Copyright © 2011-2022 走看看