【发布时间】:2021-04-24 14:20:18
【问题描述】:
我按照 web 上的一些教程使用 redis 设置 Spring Cache,
我的函数如下所示:
@Cacheable(value = "post-single", key = "#id", unless = "#result.shares < 500")
@GetMapping("/{id}")
public Post getPostByID(@PathVariable String id) throws PostNotFoundException {
log.info("get post with id {}", id);
return postService.getPostByID(id);
}
据我了解,@Cacheable 中的值是缓存名称,key 是该缓存名称中的缓存键。我也知道 Redis 是一个内存键/值存储。但是现在我对 Spring 如何将 cache name 存储到 Redis 感到困惑,因为看起来 Redis 只管理键和值,而不是缓存名称。
寻找可以向我解释的人。
提前致谢
【问题讨论】:
标签: redis spring-cache