zoukankan      html  css  js  c++  java
  • 清除缓存

    清除缓存

    #pragma mark 计算单个文件
    - (float)fileSizeAtPath:(NSString*)path {

    NSFileManager*fileManager = [NSFileManager defaultManager];

    if ([fileManager fileExistsAtPath:path]) {

    longlongsize = [fileManager attributesOfItemAtPath:path

    error:nil].fileSize;
    NSLog(@"%f",size /1024.0/

    1024.0);
    returnsize /1024.0/1024.0;

    }
    return 0;

    }

    #pragma mark 计算目录大小
    - (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];

    }

    //SDwebImage框架自身计算缓存的实现 folderSize+= [[SDImageCache

    sharedImageCache]getSize] /1024.0/1024.0; NSLog(@"------%f",folderSize);

    return folderSize;

    }
    return 0;

    }

    #pragma mark 清除缓存 - (void)clear

    {
    dispatch_async(

    dispatch_get_global_que ue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)

    , ^{

    NSString*cachPath = [NSSearchPathForDirectoriesInDomains(NSCac

    hesDirectory,NSUserDomainMask, YES) objectAtIndex:0];

    NSArray*files = [[NSFileManager defaultManager]

    subpathsAtPath:cachPath];

    NSLog(@"files :%lu" ,(unsigned long)[files count]);

    for (NSString *p in

    NSError *error;

    NSString*path = stringByAppendingPathComponent:p];

    if

    ([[NSFileManager defaultManager] fileExistsAtPath:path]) {

    [[NSFileMan ager defaultManager] removeItemAtPath:path

    error:&error];

    } }

    [self performSelectorOnMainThread:@selector(clea

    rCacheSuccess) withObject:nil waitUntilDone:YES];});
    }

    -(void)clearCacheSuccess {

    NSLog(@"清除缓存");

    files) {

    [cachPath

  • 相关阅读:
    随机-byte编码
    dataframe骚操作,待续
    oracle中的rowid
    java提高篇-----理解java的三大特性之继承
    staruml使用教程
    黑马程序员:HTML习题1
    Cocos2d-x-->CCSprite 动画
    地址栏传参中文乱码详解
    Qt学习第二天
    Lync 2010 升级到2013 之部署2013前端服务器!
  • 原文地址:https://www.cnblogs.com/lidongxiao/p/4949985.html
Copyright © 2011-2022 走看看