Spring 3.1缓存 - 如何在SpEL中使用返回值 [英] Spring 3.1 cache - how to use the returned value in the SpEL

查看:1146
本文介绍了Spring 3.1缓存 - 如何在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:

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

但是为什么你需要这样做?你可以参考@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆