BeappCache
这个库提供了一个基于RxSwift的缓存机制。目前有一个存储实现
安装
要安装它,只需将以下行添加到您的Podfile中
pod 'BeappCache'
用法
- 声明一个带所需存储实现的RxCacheManager实例
- 从RxCacheManager实例调用
fromKey
方法并定义您的键 - 将您的异步操作添加到
.withAsync()
中(⚠️ 必须为单个观察者) - 在
.withStrategy()
中定义您的缓存策略 - 获取结果(返回一个Observable)
let rxCacheManager = RxCacheManager()
rxCacheManager.fromKey(key: "key_xxx")
.withAsync(singleString)
.withStrategy(.justAsync)
.fetch()
RxCacheManager配置
详细模式
RxCacheManager(verbose: true)
- 启用RxCacheManager的详细日志
默认配置
RxCacheManager()
- 使用缓存库
- 默认的缓存配置是
DiskConfig(name: "软盘")
和MemoryConfig(expiry: .never, countLimit: 10, totalCostLimit: 10)
带有配置的缓存
RxCacheManager(storageType: .cache(config: cacheConfig))
- 使用缓存库
- 定义您的缓存配置如下
let cacheConfig = CacheStorageConfig(diskConfig: DiskConfig(name: "your_name"), memoryConfig: MemoryConfig(expiry: expiry, countLimit: Uint, totalCostLimit: Uint))
自定义存储协议
RxCacheManager(storageType: .custom(storage: YourExternalStorageProtocol()))
- 定义您自己的
ExternalStorageProtocol
结果
[BeappCache] [Cache] CacheWrapper with the key key_xxx saved
Success async request or data from cache
[BeappCache] [Cache] CacheWrapper with the key key_xxx saved
Success async request
[BeappCache] [Cache] CacheWrapper for key_xxx retrieved from cache
Success to get data from cache
作者
Beapp,[email protected]
许可证
BeappCache受MIT许可证的许可。请参阅LICENSE文件以获取更多信息。