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];

  • 相关阅读:
    sqlserver游标使用误区
    工作笔记——sqlserver引号的运用
    疯狂JAVA——数组
    工厂模式、单例和多例
    数据库数据交互详解(一)
    2016-4-6
    2016-4-5 博问问题、答题和查看收获
    Maven+Spring Batch+Apache Commons VF学习
    你忽视的静态类的作用(必看)
    Wireshark抓包工具使用教程以及常用抓包规则
  • 原文地址:https://www.cnblogs.com/gzz2016/p/5152028.html
Copyright © 2011-2022 走看看