swift - YYCache 之 YYDiskCache

本文详细介绍了YYDiskCache的初始化方法、缓存策略以及常用操作,包括设置、获取和删除缓存,并展示了如何在Swift中使用YYDiskCache进行数据缓存。
摘要由CSDN通过智能技术生成

YYDiskCache缓存是通过file文件,splits进行数据存储与读取操作,直接放代码

初始化方法:

- (nullable instancetype)initWithPath:(NSString *)path;

- (nullable instancetype)initWithPath:(NSString *)path

                      inlineThreshold:(NSUInteger)threshold

我们看两个方法的实现:

- (instancetype)initWithPath:(NSString *)path {

    return [self initWithPath:path inlineThreshold:1024 * 20]; // 20KB

}


- (instancetype)initWithPath:(NSString *)path

             inlineThreshold:(NSUInteger)threshold {

    self = [super init];

    if (!self) return nil;

    

    YYDiskCache *globalCache = _YYDiskCacheGetGlobal(path);

    if (globalCache) return globalCache;

    

    YYKVStorageType type;

    if (threshold == 0) {

        type = YYKVStorageTypeFile;

    } else if (threshold == NSUIntegerMax) {

        type = YYKVStorageTypeSQLite;

    } else {

        type = YYKVStorageTypeMixed;

    }

    

    YYKVStorage *kv = [[YYKVStorage alloc] initWithPath:path type:type];

    if (!kv) return nil;

    

    _kv = kv;

    _path = path;

   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值