Reputation: 374
How can we use static field of other class as Key in @Cachable
class Keys {
public static String CACHE_KEY = 'MY_KEY';
}
class MyClass {
@Cachable(value="TestValue",key="#Keys.CACHE_KEY")
public void method(){
}
}
Upvotes: 0
Views: 453
Reputation: 7950
Use a keyGenerator instead, although you wouldn't want a constant key obviously.
@Cachable(value="TestValue",keyGenerator ="keyGenerator")
public void method(){
}
@Bean
public KeyGenerator keyGenerator() {
return new KeyGenerator() {
@Override
public Object generate(Object o, Method method, Object... params) {
return CACHE_KEY ;
}
};
}
Upvotes: 1