public class CacheFlux extends Object
Flux in an
arbitrary cache abstraction. A generic writer/reader interface is provided, but cache
vendors that have a Map wrapper support can also be directly used.
LoadingCache graphs = Caffeine.newBuilder()
.maximumSize(10_000)
.expireAfterWrite(5, TimeUnit.MINUTES)
.refreshAfterWrite(1, TimeUnit.MINUTES)
.build(key -> createExpensiveGraph(key));
keyStream.concatMap(key -> CacheFlux.lookup(graphs.asMap(), key)
.onCacheMissResume(repository.findOneById(key))
| Constructor and Description |
|---|
CacheFlux() |
| Modifier and Type | Method and Description |
|---|---|
static <KEY,VALUE> |
lookup(reactor.cache.CacheFlux.FluxCacheReader<KEY,VALUE> reader,
KEY key)
Restore a
Flux<VALUE> from the FluxCacheReader given a provided
key. |
static <KEY,VALUE> |
lookup(Map<KEY,? super List> cacheMap,
KEY key,
Class<VALUE> valueClass)
Restore a
Flux<VALUE> from the cache-map given a provided key. |
public static <KEY,VALUE> reactor.cache.CacheFlux.FluxCacheBuilderMapMiss<VALUE> lookup(Map<KEY,? super List> cacheMap, KEY key, Class<VALUE> valueClass)
Flux<VALUE> from the cache-map given a provided key.
The cache is expected to store original values as a List of Signal
of T. If no value is in the cache, it will be calculated from the original source
which is set up in the next step. Note that if the source completes empty, this
result will be cached and all subsequent requests with the same key will return
Flux.empty(). The behaviour is similar for erroring sources, except cache
hits would then return Flux.error(Throwable).
Note that the wrapped Flux is lazy, meaning that subscribing twice in a row
to the returned Flux on an empty cache will trigger a cache miss then a
cache hit.
KEY - Key TypeVALUE - Value TypecacheMap - Map wrapper of a cachekey - mapped keybuilder step to use to set up the sourcepublic static <KEY,VALUE> reactor.cache.CacheFlux.FluxCacheBuilderCacheMiss<KEY,VALUE> lookup(reactor.cache.CacheFlux.FluxCacheReader<KEY,VALUE> reader,
KEY key)
Flux<VALUE> from the FluxCacheReader given a provided
key. The cache is expected to store original values as a List of Signal
of T. If no value is in the cache, it will be calculated from the original source
which is set up in the next step. Note that if the source completes empty, this
result will be cached and all subsequent requests with the same key will return
Flux.empty(). The behaviour is similar for erroring sources, except cache
hits would then return Flux.error(Throwable).
Note that the wrapped Flux is lazy, meaning that subscribing twice in a row
to the returned Flux on an empty cache will trigger a cache miss then a
cache hit.
KEY - Key TypeVALUE - Value Typereader - a FluxCacheReader function that looks up collection of Signal from a cachekey - mapped keybuilder step used to set up the source