Closed
Description
We are having a spring boot application and we are using redis 7.x version, cluster mode disabled.
spring-boot-starter-data-redis: 3.4.3
Configuration
public CacheManager cacheManager(RedisConnectionFactory connectionFactory) {
log.info("Initializing Redis cache manager");
var cacheRegions = redisCacheConfig.getCacheRegions();
var cacheConfigurations =
cacheRegions.stream()
.filter(CacheConfig::cachesThatHaveTTl)
.collect(
toMap(
RedisCacheConfig.Cache::getRegion,
cache ->
RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(ofSeconds(cache.getTtl()))));
return builder(connectionFactory)
.withInitialCacheConfigurations(cacheConfigurations)
.enableStatistics()
.transactionAware()
.build();
}
We have a API which perform put--->get--->get---->evict (Below method). When we hit this API. On redis server logs (Using redis-cli monitor) we found that, first two gets called, then evict and at last put and its intermittent. Is it async? How can it happen in async way? I thought above operation waits for each other to complete.
Important Note: I am using @transactional
public void put(String cacheName, String key, Object value) {
Cache cache = cacheManager.getCache(cacheName);
if (nonNull(cache)) {
cache.put(key, value);
// Increment cache update counter
registerUpdate(cacheName);
}
}
public Object get(String cacheName, String key) {
Cache cache = cacheManager.getCache(cacheName);
if (nonNull(cache)) {
Cache.ValueWrapper valueWrapper = cache.get(key);
if (nonNull(valueWrapper)) {
registerHit(cacheName);
return valueWrapper.get();
} else {
// Increment cache miss counter
registerMiss(cacheName);
}
}
return null;
}
public void evict(String cacheName, String key) {
Cache cache = cacheManager.getCache(cacheName);
if (nonNull(cache)) {
cache.evictIfPresent(key);
registerEvict(cacheName);
}
}