Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 仅在特定方法调用时搜索缓存数据_Java_Spring_Caching_Spring Boot_Ehcache - Fatal编程技术网

Java 仅在特定方法调用时搜索缓存数据

Java 仅在特定方法调用时搜索缓存数据,java,spring,caching,spring-boot,ehcache,Java,Spring,Caching,Spring Boot,Ehcache,我想知道是否只有在从特定方法调用时才能获取缓存数据,例如我有一个方法被注释为@Cacheable,我希望它只在特定方法调用时返回缓存的内容,否则,正常执行该方法。使用Spring cache抽象。 通过这种方式,any Spring缓存从方法返回的对象,方法输入作为键。所以这个方法被称为用户从缓存中返回,如果找到了,或者实际的方法被称为响应被缓存并返回 这可以由任何第三方缓存支持,如redis、ehcache、hazelcast 是的,您可以使用@Cacheable注释的条件参数来完成。请查看

我想知道是否只有在从特定方法调用时才能获取缓存数据,例如我有一个方法被注释为@Cacheable,我希望它只在特定方法调用时返回缓存的内容,否则,正常执行该方法。

使用Spring cache抽象。

通过这种方式,any Spring缓存从方法返回的对象,方法输入作为键。所以这个方法被称为用户从缓存中返回,如果找到了,或者实际的方法被称为响应被缓存并返回


这可以由任何第三方缓存支持,如redis、ehcache、hazelcast

是的,您可以使用
@Cacheable
注释的条件参数来完成。请查看第28.3.1.3节

对不起,您能解释一下这个问题的答案吗。当从任何方法(使用相同参数)调用时,您所指示的代码段将返回缓存对象。但问题有所不同。当从特定方法调用缓存的方法(带有@Cacheable)时,只需返回缓存项,否则它应该遵循方法内部的常规代码流。对不起,如果我遗漏了什么。
@Cacheable({"users"})
public User getUser(String userId) {
// Logic goes here
}