zoukankan      html  css  js  c++  java
  • 0122 清楚缓存

    //start

    -(void)clearCashSelf{

        MCLog(@"NSHomeDirectory 沙盒路径----%@",NSHomeDirectory());

        

    //    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"清除缓存" message: [NSString stringWithFormat:@"清除%.2fM",fileSizeM] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"清除本地缓存" message: [NSString stringWithFormat:@"清除%.2fKB",fileSizeM] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

        alert.tag = 8899;

        [alert show];

        

    }

    -(float)fileSizeAtPath:(NSString *)path{

        NSFileManager *fileManager=[NSFileManager defaultManager];

        if([fileManager fileExistsAtPath:path]){

            long long size=[fileManager attributesOfItemAtPath:path error:nil].fileSize;

    //        return size/1024.0/1024.0;

            return size/1024.0;

        }

        return 0;

    }

    -(float)folderSizeAtPath:(NSString *)path{

        NSFileManager *fileManager=[NSFileManager defaultManager];

        float folderSize;

        if ([fileManager fileExistsAtPath:path]) {

            NSArray *childerFiles=[fileManager subpathsAtPath:path];

            for (NSString *fileName in childerFiles) {

                NSString *absolutePath=[path stringByAppendingPathComponent:fileName];

                folderSize +=[self fileSizeAtPath:absolutePath];

            }

           

            return folderSize;

        }

        return 0;

    }

    -(void)clearCache:(NSString *)path{

        

        NSFileManager *fileManager=[NSFileManager defaultManager];

        if ([fileManager fileExistsAtPath:path]) {

            NSArray *childerFiles=[fileManager subpathsAtPath:path];

            for (NSString *fileName in childerFiles) {

                //如有需要,加入条件,过滤掉不想删除的文件

                NSString *absolutePath=[path stringByAppendingPathComponent:fileName];

                [fileManager removeItemAtPath:absolutePath error:nil];

            }

        }

            [[SDImageCache sharedImageCache] cleanDisk];

    }

                    [self clearCashSelf];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);

                NSString *cachPath = [paths objectAtIndex:0];

                

                [self clearCache:cachPath];

                fileSizeM=0;

    //            [TvDataArray removeAllObjects];

                [_TVSatand reloadData];

  • 相关阅读:
    吴裕雄--天生自然 Zookeeper学习笔记--ZooKeeper 数据模型 znode 结构详解
    吴裕雄--天生自然 Zookeeper学习笔记--Zookeeper Java 客户端搭建
    吴裕雄--天生自然 Zookeeper学习笔记--Zookeeper linux 服务端集群搭建步骤
    吴裕雄--天生自然 Zookeeper学习笔记--Zookeeper 安装配置
    吴裕雄--天生自然 Zookeeper学习笔记--ZooKeeper
    吴裕雄--天生自然 使用python的pandas_alive包生成动态图
    程序规范示例
    迭代器Iteration
    斐波拉契数列(Fibonacci)--用生成器生成数列
    Python中装饰器的用法
  • 原文地址:https://www.cnblogs.com/gzz2016/p/5152028.html
Copyright © 2011-2022 走看看