Spring 3.1 cache - how to use the returned value in the SpEL

倾然丶 夕夏残阳落幕 提交于 2019-12-03 19:05:00

It doesn't seem like there is any way to reference the returned object:

http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/cache.html#cache-spel-context

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 {
...
}

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 {
...
}

try using #result in your SpEL

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!