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

  • 相关阅读:
    文件操作和网络通信
    h4和c2的简单内容
    Node介绍
    终端命令和环境变量
    C#连接MySQL数据库方法
    多点触控
    wp7全景控件
    Silverlight数据绑定转换示例
    Windows Phone 7两个页面动画跳转
    使用.NET操作SQLLITE
  • 原文地址:https://www.cnblogs.com/lidongxiao/p/4949985.html
Copyright © 2011-2022 走看看