gpt4 book ai didi

java - Spring 3.1缓存——如何在SpEL中使用返回值

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:57:24 24 4
gpt4 key购买 nike

我正在尝试逐出 Spring 管理的缓存中的条目(Spring 3.1 抽象)。

我需要在注解中引用“key”属性的SpEL中方法的返回值:

    /* (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);
}

有什么办法吗?

最佳答案

似乎没有任何方法可以引用返回的对象:

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

但是为什么你需要这样做呢?您可以引用@CacheEvict "key"值中的参数,例如:

@CacheEvict(value = CACHE_BY_ID, key = "#userID")
public T delete(AppID appID, UserID userID) throws UserNotFoundException {
...
}

响应以下有关必须使用用户对象的多个属性从多个缓存中逐出的响应的更多示例代码:

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

关于java - Spring 3.1缓存——如何在SpEL中使用返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10678524/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com