I am able to cache the DB entity, but when I update it and do a get call to the same entity, I receive the stale the entity in response. Am I missing come configuration here?
BTW I am trying to implement L2 cache to be used by hibernate for performance improvement.
RedisConfig.java
@Configuration@EnableCachingpublic class RedisConfig { @Value("${spring.redis.port}") int redisPort; @Value("${spring.redis.host}") String redisHost; @Bean public JedisConnectionFactory jedisConnectionFactory() { RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); redisStandaloneConfiguration.setHostName(redisHost); redisStandaloneConfiguration.setPort(redisPort); return new JedisConnectionFactory(redisStandaloneConfiguration); } @Bean public LettuceConnectionFactory redisConnectionFactory() { return new LettuceConnectionFactory(redisHost, redisPort); } @Bean public RedisTemplate<String, Object> redisTemplate() { RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(redisConnectionFactory()); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setHashKeySerializer(new StringRedisSerializer()); redisTemplate.setHashKeySerializer(new JdkSerializationRedisSerializer()); redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); redisTemplate.setEnableTransactionSupport(true); redisTemplate.afterPropertiesSet(); return redisTemplate; }}
Application.yml
spring: datasource: driver-class-name: org.mariadb.jdbc.Driver url: jdbc:mariadb://localhost:3306/ username: root password: jpa: properties: hibernate: cache: use_second_level_cache: true region: factory_class: org.redisson.hibernate.RedissonRegionFactory redisson: fallback: true config: redisson-dev.yaml redis: host: localhost port: 6379 cache: type: redis
redisson-dev.yaml
singleServerConfig: address: "redis://localhost:6379"
Entity Class
@Entity@Getter@Setter@EqualsAndHashCode(callSuper=false)@Slf4j@org.hibernate.annotations.Cache(region="userCache", usage = CacheConcurrencyStrategy.READ_WRITE)@Table(name="user")public class userEntity extends BaseEntity implements Serializable { @Id @Column(name = "user_id") @Type(type = "uuid-char") private UUID userId;//Binary in DB and UUID here...}