public class CacheMono extends Object
Mono 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.
Example usage:
LoadingCache graphs = Caffeine.newBuilder()
.maximumSize(10_000)
.expireAfterWrite(5, TimeUnit.MINUTES)
.refreshAfterWrite(1, TimeUnit.MINUTES)
.build(key -> createExpensiveGraph(key));
keyStream.concatMap(key -> CacheMono.lookup(graphs.asMap(), key)
.onCacheMissResume(repository.findOneById(key))
| Constructor and Description |
|---|
CacheMono() |
| Modifier and Type | Method and Description |
|---|---|
static <KEY,VALUE> |
lookup(reactor.cache.CacheMono.MonoCacheReader<KEY,VALUE> reader,
KEY key)
Restore a
Mono<VALUE> from the MonoCacheReader given a provided
key. |
static <KEY,VALUE> |
lookup(Map<KEY,? super reactor.core.publisher.Signal<? extends VALUE>> cacheMap,
KEY key)
Restore a
Mono<VALUE> from the cache-map given a provided key. |
public static <KEY,VALUE> reactor.cache.CacheMono.MonoCacheBuilderMapMiss<VALUE> lookup(Map<KEY,? super reactor.core.publisher.Signal<? extends VALUE>> cacheMap, KEY key)
Mono<VALUE> from the cache-map given a provided key. 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 Mono.empty(). The
behaviour is similar for erroring sources, except cache hits would then return
Mono.error(Throwable).
Note that the wrapped Mono is lazy, meaning that subscribing twice in a row
to the returned Mono 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.CacheMono.MonoCacheBuilderCacheMiss<KEY,VALUE> lookup(reactor.cache.CacheMono.MonoCacheReader<KEY,VALUE> reader,
KEY key)
Mono<VALUE> from the MonoCacheReader given a provided
key. 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
Mono.empty(). The behaviour is similar for erroring sources, except cache
hits would then return Mono.error(Throwable).
Note that the wrapped Mono is lazy, meaning that subscribing twice in a row
to the returned Mono on an empty cache will trigger a cache miss then a
cache hit.
KEY - Key TypeVALUE - Value Typereader - a MonoCacheReader function that looks up Signal from a cachekey - mapped keybuilder step to use to set up the source