Skip to content

A collection of caching/memoizing RxSwift map operators.

License

Notifications You must be signed in to change notification settings

BrianSemiglia/RxCacheMap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RxCacheMap

CI Status Version License Platform

Description

Cache/memoize the output of RxSwift.Observables using cacheMap, cacheFlatMap, cacheFlatMapLatest and cacheFlatMapUntilExpired. Also available for Combine: https://github.com/BrianSemiglia/CombineCacheMap

Usage

Aside from caching, all functions work like their non-cache Rx-counterparts.

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

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

events.cacheFlatMapInvalidatingOn { x -> Observable<(Value, 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 -> Value in
    expensiveOperation(x)
}

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

RxCacheMap is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'RxCacheMap'

Author

[email protected]

License

RxCacheMap is available under the MIT license. See the LICENSE file for more info.

About

A collection of caching/memoizing RxSwift map operators.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published