Spring caching uses key
parameter as the cache key or the parameter passed to the function if key
is not present. What will be the key
if both the key and function parameter are missing?
Consider the folllowing case where neither key
parameter nor function parameter exists. How spring caching work in such a case?
@Cacheable(value="cacheTest")
public string sayHello(){
return "hello"
}
See the current Spring Cache Abstraction documentation on the subject of cache keys, here.
In a nutshell...
"If no params are given, return SimpleKey.EMPTY."
In your case, Spring will create an "empty" SimpleKey
(i.e. SimpleKey.EMPTY
) as the cache key for the result ("hello") of your sayHello()
@Cacheable
service method.
By way of example, see this test case.