【发布时间】:2019-01-31 08:34:20
【问题描述】:
我已经使用spring @Cacheable 进行缓存,如下所示:
@Cacheable
public Response mycall(Request request)
现在我希望仅当 request.getId()!=3 时才缓存此方法调用,其中 getId()
是 Request 类中的公共 getter 方法。
我看到人们在@Cacheable 中指定了unless 条件的代码,但我看到仅在方法的响应上而不是在请求上指定条件。参考:How do I tell Spring cache not to cache null value in @Cacheable annotation
在请求的字段上指定条件时,有什么方法可以达到同样的效果
【问题讨论】:
-
你不想要像
unless="#request.id == 3"这样的东西吗?看起来参数可以按名称使用,结果是名称“#result”,在除非表达式中... -
我试过了,不行
标签: java spring spring-data