BeappCache 0.6

BeappCache 0.6

Cedric GuinoiseauCédric DeracheBeapp维护。



 
依赖于
缓存~> 5.2.0
RxSwift~> 6.0
 

  • 作者
  • beapp

BeappCache

这个库提供了一个基于RxSwift的缓存机制。目前有一个存储实现

安装

要安装它,只需将以下行添加到您的Podfile中

pod 'BeappCache'

用法

  1. 声明一个带所需存储实现的RxCacheManager实例
  2. 从RxCacheManager实例调用fromKey方法并定义您的键
  3. 将您的异步操作添加到.withAsync()中(⚠️必须为单个观察者)
  4. .withStrategy()中定义您的缓存策略
  5. 获取结果(返回一个Observable)
let rxCacheManager = RxCacheManager()
rxCacheManager.fromKey(key: "key_xxx")
.withAsync(singleString)
.withStrategy(.justAsync)
.fetch()

RxCacheManager配置

详细模式

  • RxCacheManager(verbose: true)
  1. 启用RxCacheManager的详细日志

默认配置

  • RxCacheManager()
  1. 使用缓存库
  2. 默认的缓存配置是 DiskConfig(name: "软盘")MemoryConfig(expiry: .never, countLimit: 10, totalCostLimit: 10)

带有配置的缓存

  • RxCacheManager(storageType: .cache(config: cacheConfig))
  1. 使用缓存库
  2. 定义您的缓存配置如下 let cacheConfig = CacheStorageConfig(diskConfig: DiskConfig(name: "your_name"), memoryConfig: MemoryConfig(expiry: expiry, countLimit: Uint, totalCostLimit: Uint))

自定义存储协议

  • RxCacheManager(storageType: .custom(storage: YourExternalStorageProtocol()))
  1. 定义您自己的 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,

许可证

BeappCache受MIT许可证的许可。请参阅LICENSE文件以获取更多信息。