我必须实现Redis进行缓存管理。我正在追踪this 教程,但是问题是,当我在控制器方法上使用@Cacheable批注时,它为我提供了404状态代码。
我的控制器方法如下:
@GetMapping("auth/cache/{id}")
@Cacheable("test")
public ServiceResponse<String> checkingCache(@PathVariable("id") Integer id){
return new ServiceResponse<>(new String("String with id "+id));
}
当我删除可缓存的注释时,该方法将按预期工作。
我在机器上安装了redis,它在默认端口上运行。 Redis的配置如下:
spring.cache.type=redis
spring.redis.host=localhost
spring.redis.port=6379
我缺少什么吗?任何帮助将不胜感激,谢谢!
答案 0 :(得分:0)
已启用教程中介绍的带有注释Select
path.path.reason,
path.path.string
From table_name
Where path.id = '123'
And datestr = '2018-07-21'
的缓存。
此外,由于您需要缓存特定的ID,因此必须提供该密钥以进行缓存。您的示例应为:
@EnableCaching
如果您没有@GetMapping("auth/cache/{id}")
@Cacheable(value = "test", key = "#id")
public ServiceResponse<String> checkingCache(@PathVariable("id") Integer id){
return new ServiceResponse<>(new String("String with id "+id));
}
,则可以在没有密钥的情况下注释@PathVariable