Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Cached、@CacheUpdate中的key、value是否像postCondition 、condition可以使用SpEL访问到#result对象? #867

Open
liumangafei opened this issue Mar 21, 2024 · 4 comments

Comments

@liumangafei
Copy link

如标题,是否可以下面这样使用?

例子:
@cached(key="#result.id", value="#result")

我在文档中没有发现key、value中有提到可以使用#result
但我需求是在dao层,insert、update方法入参对象不完整,返回的对象才是我想要缓存的对象,不知是否支持?

@areyouok
Copy link
Collaborator

这是个先有鸡还是先有蛋的问题,key要先进行评估,然后才决定要不要执行方法(或者使用cache里面的数据返回),你都没有执行怎么会有result呢?

@liumangafei
Copy link
Author

这是个先有鸡还是先有蛋的问题,key要先进行评估,然后才决定要不要执行方法(或者使用cache里面的数据返回),你都没有执行怎么会有result呢?

谢谢大佬答复。

我完整些举例表达,防止歧义:

@cached(key="#result.id", value="#result", postCondition="#result.id != null")
User insert(User example);

@CacheUpdate(key="#result.id", value="#result", condition="#result.id != null")
User update(User example);

两个例子中,实际都想表达方法执行后,缓存或更新方法结果;
由于@cached、@CacheUpdate文档中key、value未说明是否可以引用到#result,所以特此请教这样使用是否可以有效。

@areyouok
Copy link
Collaborator

key和value的表达式不能访问result,另外cached注解没有value这个属性。

你有特殊需要可以直接用api,不一定非要和注解死磕

@liumangafei
Copy link
Author

key和value的表达式不能访问result,另外cached注解没有value这个属性。

你有特殊需要可以直接用api,不一定非要和注解死磕

好的,感谢大佬;
讲解很清晰。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants