spring-data-redis-reactive

ReactiveRedisTemplate Cache Miss


How do we handle cache miss scenario using ReactiveRedisTemplate<String, String>? Also, need to log and treat any error from underlying Redis cache as cache miss.

please suggest.


Solution

  • It's hard to say without a code example, but you can utilize the operator .switchIfEmpty(). You'll need to defer the Mono so it's lazy loaded and only evaluated after the Redis template returns something.

    .switchIfEmpty(Mono.defer(() -> callMethodToFetchData());