美文网首页
iOS---获取缓存数据

iOS---获取缓存数据

作者: 不可雕的板蓝根 | 来源:发表于2018-07-06 15:19 被阅读0次
    + (CGFloat)getCachSize {
        
        NSUInteger imageCacheSize = [[SDImageCache sharedImageCache] getSize];
        //获取自定义缓存大小
        //用枚举器遍历 一个文件夹的内容
        //1.获取 文件夹枚举器
        NSString *myCachePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"];
        NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:myCachePath];
        __block NSUInteger count = 0;
        //2.遍历
        for (NSString *fileName in enumerator) {
            NSString *path = [myCachePath stringByAppendingPathComponent:fileName];
            NSDictionary *fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];
            count += fileDict.fileSize;//自定义所有缓存大小
        }
        // 得到是字节  转化为M
        CGFloat totalSize = ((CGFloat)imageCacheSize+count)/1024/1024;
        return totalSize;
    }
    

    相关文章

      网友评论

          本文标题:iOS---获取缓存数据

          本文链接:https://www.haomeiwen.com/subject/awypuftx.html