2015-07-03 165 views
1

我使用@Cacheable注释从下方获取电影列表。由于它没有任何参数,因此我将键设置为#root.method.name。如何使用带@Cacheable注解的@CachePut?

@Cacheable(value="movieFindCache", key = "#root.method.name") 
public List<Movie> getMovies(){ 
    ... 
    return movies; 
} 

现在我想添加一个新电影,同样应该被添加到上面的缓存。

@CachePut(value="movieFindCache", key="getMovies") 
public void addNewMovie(){ 
    // create and add new movie to movies list 
} 

我试过这个,但它给了我例外。

org.springframework.expression.spel.SpelEvaluationException: 
Property or field 'getMovies' cannot be found on object of type 'org.springframework.cache.interceptor.CacheExpressionRootObject' - maybe not public? 

我们可以在这里使用@CachePut批注还是有其他方法可以做到这一点?

回答

相关问题