java - 如何通过使用@Cacheable 注解实现以下行为?
问题描述
假设我有一个从 Mongo 获取数据的方法,可以缓存到 redis 中。
@Cacheable
public List<Values> cacheValues(List<String> input){
// code that fetches the list based on input from mongodb
}
问题是有一个文档列表对应于 mongo db 中的每个特定输入。从 mongo 获取时,所有列表都合并为一个列表。有什么方法可以告诉@Cacheable 注解必须以相同的方式持久化和获取数据?或者有什么方法可以自定义@Cacheable 以便能够使用我们自己的redis 操作来获取和持久化?我正在使用弹簧数据 redis。
第二个问题:如何根据输入中的值创建密钥。例如:
@Cacheable(cacheNames = "cach1", key = "input[0] + …. input[input.size-1]")
public List<Values> cacheValues(List<String> input){
// code that fetches the list based on input from mongodb
}
解决方案
推荐阅读
- asp.net-core-mvc - 如何显示从视图到控制器的嵌套视图模型
- node.js - 如何在 nodejs 中运行任务,我得到 npm 运行错误
- java - mvvmFX 在 Maven 项目中找不到 FXML 文件
- python - PyQt+Socket - 为 GUI 服务器的多线程客户端运行循环
- ruby-on-rails - Rails 错误消息显示太多细节
- javascript - Shopify 检索有关特定产品的数据
- c++ - 如何枚举远程计算机上的卷?
- javascript - 开玩笑防止节点模块被导入
- visual-studio-2019 - Visual Studio 2019 发布(或从服务器替换)单个选定文件不可用
- python - 如何通过 Pandas 中的循环加入多个 DataFrame?