Spring 3.1缓存 - 如何在SpEL中使用返回值 [英] Spring 3.1 cache - how to use the returned value in the SpEL
问题描述
我试图在Spring管理的缓存(Spring 3.1抽象)中驱逐一个条目。
I am trying to make an eviction of an entry in a Spring-managed cache (Spring 3.1 abstraction).
我需要在注释中的key属性的SpEL中引用该方法的返回值:
I need to refer to the returned value of the method in the SpEL of the "key" property in the annotation:
/* (How to refer to the 'T' returned value in the "KEY_ID"?) */
@Caching(evict = { @CacheEvict(value = CACHE_BY_ID, key = KEY_ID) })
public T delete(AppID appID, UserID userID) throws UserNotFoundException {
return inner.delete(appID, userID);
}
有没有办法做到这一点?
Is there any way to do this?
推荐答案
似乎没有办法引用返回的对象:
It doesn't seem like there is any way to reference the returned object:
但是为什么你需要这样做?你可以参考@CacheEvictkey值中的参数,例如:
But why do you need to do that? You can refer to the arguments in the @CacheEvict "key" value, e.g.:
@CacheEvict(value = CACHE_BY_ID, key = "#userID")
public T delete(AppID appID, UserID userID) throws UserNotFoundException {
...
}
响应以下响应的更多示例代码,关于必须使用User对象的多个属性从多个缓存中逐出:
More example code in response to response below about having to evict from multiple caches using multiple properties of a User object:
@Caching(evict = {
@CacheEvict(value = CACHE_BY_ID, key = "#user.userID"),
@CacheEvict(value = CACHE_BY_LOGIN_NAME, key = "#user.loginName")
// etc.
})
public T delete(AppID appID, User user) throws UserNotFoundException {
...
}
这篇关于Spring 3.1缓存 - 如何在SpEL中使用返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!