Reputation: 3717
I am fetching a list of movies from below method with @Cacheable annotation. Since it does not have any parameter, I set key as #root.method.name.
@Cacheable(value="movieFindCache", key = "#root.method.name")
public List<Movie> getMovies(){
...
return movies;
}
Now I want to add a new movie and same should be added to above cache.
@CachePut(value="movieFindCache", key="getMovies")
public void addNewMovie(){
// create and add new movie to movies list
}
I tried this but it is giving me exception.
org.springframework.expression.spel.SpelEvaluationException:
Property or field 'getMovies' cannot be found on object of type 'org.springframework.cache.interceptor.CacheExpressionRootObject' - maybe not public?
Can we use @CachePut annotation here or there is some other way to do it?
Upvotes: 1
Views: 1542
Reputation: 348
key
is an Spring Expression language http://docs.spring.io/spring/docs/current/spring-framework-reference/html/expressions.html
Try ''
@CachePut(value="movieFindCache", key="'getMovies'")
Upvotes: 1