Spring缓存。如果没有键和参数,缓存键是什么

Spring Caching. what is the cache key if there is no key as well as parameter

Spring 缓存使用 key 参数作为缓存键或如果 key 不存在则传递给函数的参数。如果缺少键和函数参数,key 会是什么?

考虑以下情况,其中 key 参数和函数参数都不存在。在这种情况下,spring 缓存如何工作?

@Cacheable(value="cacheTest")
public string sayHello(){
    return "hello"
}

请参阅有关缓存键主题的当前 Spring 缓存抽象 文档,here

简而言之...

"If no params are given, return SimpleKey.EMPTY."

在您的情况下,Spring 将创建一个“空”SimpleKey(即 SimpleKey.EMPTY)作为结果的缓存键("hello") 您的 sayHello() @Cacheable 服务方法。

例如,请参阅此 test case