我在我的本地机器上使用 redis 缓存作为 docker 镜像。我使用可缓存的 anothion 为我的方法之一启用了缓存。当我在 aws 上使用它而不是本地主机时,应用程序无法缓存相同内容
public class RedisConfig {
@Autowired
private JedisConnectionFactory jedisConnectionFactory;
@Bean
public RedisTemplate<Object, Object> redisTemplate() {
System.out.println("localhost")
System.out.println("6379");
jedisConnectionFactory.getHostName();
jedisConnectionFactory.getPort();
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory);
template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
return template;
}
@Bean
public CacheManager cacheManager(RedisTemplate redisTemplate) {
RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
// Number of seconds before expiration. Defaults to unlimited (0)
cacheManager.setDefaultExpiration(60);
cacheManager.setUsePrefix(true);
return cacheManager;
}
}
@Cacheable(value="sgcode" , cacheManager ="cacheManager")
public String getSegmentCode(String aname ) {
Logger.info("code ", "##### SEGMENT METHOD CALLED ##### {}", aname);
return segmentCodeMap.get(aname);
}
Logger line will be printed only once after that it should fetch from cache.
最佳答案
经过一番努力终于找到了根本原因。在应用程序类中使用 enablecaching 注释
关于spring - 带有 spring boot 的 Redis 缓存 docker 容器在我的本地机器上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52041380/