I am using the Spring Cache default implementation(ConcurrentHashMap):
@Bean
CacheManager cacheManager() {
ConcurrentMapCacheManager cacheManager = new ConcurrentMapCacheManager("mycache");
cacheManager.setAllowNullValues(false);
return cacheManager;
}
Reactor addons is used to get an item. On cache miss item is written to the cache:
public Mono<T> get(ID key) {
return CacheMono.lookup(k -> findValue(k).map(Signal::next), key)
.onCacheMissResume(Mono.defer(valueRetriever(key)))
.andWriteWith((k, signal) -> Mono.fromRunnable(() -> {
if (!signal.isOnError()) {
writeValue(k, signal.get());
}
}));
}
private void writeValue(ID key, T value) {
if (value != null) {
cache.put(key, value);
}
}
Does cache.put(key, value); considered a blocking call? Should be published on a different Scheduler?