@Cacheable key是两个字符串
时间: 2024-01-01 15:04:10 浏览: 74
@Cacheable注解是Spring框架中用于缓存方法结果的注解。根据引用[2]中的描述,当有两个入参,并且我们希望以这两个参数同时作为缓存的key区分时,可以使用如下方式设置@Cacheable注解的key属性:
```java
@Cacheable(cacheNames = "cacheName", key = "#param1 + '_' + #param2")
```
其中,`param1`和`param2`分别代表方法的两个参数。通过在key属性中使用`+`来拼接两个参数的值,以生成唯一的缓存key。这样就可以实现根据两个字符串参数来区分缓存了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [详解Spring缓存注解@Cacheable,@CachePut , @CacheEvict使用](https://download.csdn.net/download/weixin_38611877/12781025)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [@Cacheable keyGenerator 自定义参数作为key](https://blog.csdn.net/weixin_46305078/article/details/131556245)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文