Skip to content

Instantly share code, notes, and snippets.

@sirech
Created May 8, 2022 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirech/8709bea9d4080f479ed79255c7dd6369 to your computer and use it in GitHub Desktop.
Save sirech/8709bea9d4080f479ed79255c7dd6369 to your computer and use it in GitHub Desktop.
private T getFromCacheOrThrow(String key, RuntimeException exception) {
var value = cache.findById(key);
value.ifPresent((v) -> {
log.info(String.format("FallbackCache[%s] got cached value", cb.getName()), v);
});
return value
.map(Cacheable::data)
.orElseThrow(() -> {
log.error(
String.format("FallbackCache[%s] got an error without a cached value", cb.getName()),
exception
);
throw exception;
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment