【问题标题】:How to use regex in SpEL while evicting specific keys which match the regex in key attribute of @CacheEvict如何在 SpEL 中使用正则表达式,同时驱逐与 @CacheEvict 的键属性中的正则表达式匹配的特定键
【发布时间】:2016-09-18 22:56:58
【问题描述】:

我想为给定的缓存逐出以某个字符串开头的所有键 例如:

@CacheEvict(cacheNames="LOCATION", key="#p0*")
public void evictLocation(String location, String type ) {
    //some code here
}

我想逐出所有具有以传入参数的位置开头的键的缓存对象。 我尝试使用 * 量词,但它不起作用

【问题讨论】:

标签: spring spring-cache


【解决方案1】:

您可以在SpEL表达式中使用正则表达式,请尝试在您的键值中添加#{},---

@CacheEvict(cacheNames="LOCATION", key="#{yourLocationArg*}")
public void evictLocation(String location, String type ) {
    //some code here
}

【讨论】:

  • 这似乎不起作用我尝试了以下方式@CacheEvict(cacheNames="LOCATION", key="#{p0*}") 但没有发生驱逐
  • 请详细说明
  • @Liping Huang 这真的有用吗?你能分享更多代码吗?
猜你喜欢
  • 2018-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-06
  • 2018-11-05
相关资源
最近更新 更多