如何在 SpEL 中使用正则表达式,同时逐出与 @CacheEvict 的键属性中的正则表达式匹配的特定键

How to use regex in SpEL while evicting specific keys which match the regex in key attribute of @CacheEvict

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

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

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

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

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