RxCacheMap 1.0.1

RxCacheMap 1.0.1

Brian Semiglia 维护。



RxCacheMap

CI Status Version License Platform

描述

使用 cacheMap、cacheFlatMap、cacheFlatMapLatest 和 cacheFlatMapUntilExpired 缓存 RxSwift.Observables 的输出。

用法

除了缓存之外,所有功能与非缓存版本的 Rx 相同。

events.cacheMap { x -> Result in
    // Closure executed once per unique `x`, replayed when not unique.
    expensiveOperation(x)
}

events.cacheMap(whenExceeding: .seconds(1)) { x -> Result in
    // Closure executed once per unique `x`, replayed when operation of unique value took 
    // longer than specified duration.
    expensiveOperation(x)
}

events.cacheFlatMapInvalidatingOn { x -> Observable<(Result, Date)> in
    // Closure executed once per unique `x`, replayed when input not unique. Cache 
    // invalidated when date returned is greater than or equal to date of event.
    expensiveOperation(x).map { output in 
        return (output, Date() + hours(1))
    }
}

// You can provide your own cache (disk, in-memory, etc.). NSCache is the default.
events.cacheMap(cache: MyCache()) { x -> Result in
    expensiveOperation(x)
}

示例

要运行示例项目,请克隆仓库,然后从 Example 目录中首先运行 pod install

安装

RxCacheMap 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'RxCacheMap'

作者

[email protected]

许可证

RxCacheMap遵循MIT许可证。有关更多信息,请参阅LICENSE文件。