I have reached a conflict situation between Spring @Repository and @Cacheable.
@Service
public class ServiceA{
@Cacheable("cacheName")
public Response getResponse(){
}
}
@EnableCaching
public class SpringBootApplication {
...
}
@Repository
public class RedisRepository{
public void setSomething(){
}
public Something getSomething(){
}
}
@Configuration
@EnableRedisRepositories
public class RedisConfig {
@Bean
public JedisConnectionFactory connectionFactory() {
}
@Bean
public RedisTemplate<String, Object> redisTemplate() {
}
}
The case is that with that configuration, the In-Memory cache is ignored and my cache is stored in the remote Redis DB.
How can I keep the in-memory cache and don't use remote Redis for caching?
I figured out this is not a bug but a feature. When spring detects spring-data-redis in the dependencies, it automatically enables distributed caching using redis by default. Thus, I had to set spring.cache.type=simple in application.properties
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>