Reputation: 2128
As part of my code I have a method with empty parameters. For e..g,
public MasterData fetchMasterData() {
// DO something.
}
I want to add a @Cacheable with key as 'masterdata'. I tried the following, but it looks for a bean named 'masterdata'.
I tried @Cacheable(cache="master", key="masterdata")
If I leave the key attribute, I know it takes as empty key. But I want to explicitly give a constant as key.
Is there a way to do that?
Upvotes: 10
Views: 6510
Reputation: 33091
The key
attribute is a SpEL expression so if you want the key to be masterdata
you would write something like this
@Cacheable(cache="master", key="'masterdata'")
public MasterData fetchMasterData() { ... }
Upvotes: 26