Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.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/7/python-2.7/5.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_Spring Boot_Caching_Ehcache - Fatal编程技术网

Java 如果方法参数为接口,如何生成缓存键

Java 如果方法参数为接口,如何生成缓存键,java,spring,spring-boot,caching,ehcache,Java,Spring,Spring Boot,Caching,Ehcache,我有一个方法,它接受org.springframework.data.domain.Pageable作为参数。 当用户请求page=0和size=20等等时,我希望将这些传递的值设置为缓存键 我所做的是 @Cacheable(key = "#pageable.number") public Person getPersons(Pageable pageable) 这给了我们一个惊喜: EL1008E:在类型为的对象上找不到属性或字段“number” “org.springframework.

我有一个方法,它接受
org.springframework.data.domain.Pageable
作为参数。 当用户请求page=0和size=20等等时,我希望将这些传递的值设置为
缓存键

我所做的是

@Cacheable(key = "#pageable.number")
public Person getPersons(Pageable pageable) 
这给了我们一个惊喜:

EL1008E:在类型为的对象上找不到属性或字段“number” “org.springframework.data.domain.PageRequest”-可能不是公共的


如何设置缓存键?

该属性称为
pageNumber
而不是
number

@Cacheable(key = "#pageable.pageNumber")
public Person getPersons(Pageable pageable) 

不过,以这种方式使用缓存的一般意义可能会受到质疑。但这可能超出了这个问题的范围。

这很有效!!!什么是
这种方式使用缓存的一般意义可能会受到质疑。请添加此项,这将非常有帮助。首先,我希望这只是伪代码,您实际返回的是
页面
集合
,而不是单个
个人
对象。然后还要对缓存失效进行彻底的处理,否则最终会得到过时的数据。