Created
December 11, 2019 07:43
-
-
Save stefanotroia/4470950b0debe0236571edec5daaa824 to your computer and use it in GitHub Desktop.
base service with caching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
@Slf4j | |
public class BaseService<E extends GenericEntity> { | |
@Autowired | |
protected HazlecastService hazlecastService; | |
public Mono<E> findCacheValue(String cacheName, List<String> keys, Mono<E> fallBackMono) { | |
return CacheMono | |
.lookup(k -> findCacheValue(cacheName, keys).map(Signal::next), keys) | |
.onCacheMissResume(fallBackMono) | |
.andWriteWith((k, sig) -> Mono.fromRunnable(() -> | |
writeCacheValue(cacheName,keys,sig.get()))); | |
} | |
public Mono<E> writeCacheValue(String cacheName, List<String> keys, E data) { | |
if(data != null) { | |
hazlecastService.getHzInstance().getMap(cacheName).set(createKey(keys),data); | |
return Mono.just(data); | |
} | |
return Mono.empty(); | |
} | |
public Flux<E> writeCacheValues(String cacheName, List<String> keys, List<E> data) { | |
hazlecastService.getHzInstance().getMap(cacheName).set(createKey(keys),data); | |
return Flux.fromIterable(data); | |
} | |
public void evictValue(String cacheName, List<String> keys) { | |
hazlecastService.getHzInstance().getMap(cacheName).evict(createKey(keys)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, is this method calling itself, can you please highlight what is going on here?