【问题标题】:Calling @cacheEvict and @Cacheable together SpringSpring同时调用@cacheEvict和@Cacheable
【发布时间】:2013-12-31 08:48:03
【问题描述】:

这可能很简单,但我想知道我是否可以通过以下一种方法同时调用@Cacheable 和@CacheEvict:

@Cacheable(value = "empListCache")
@CacheEvict(value = "empListCache", allEntries = true)
public List<Emply> findAllEmplys() throws SomeException

上面的代码是在每次调用方法时驱逐empListCache还是只在缓存满时才被驱逐?

谢谢。

【问题讨论】:

    标签: caching ehcache spring-annotations spring-cache


    【解决方案1】:

    你到底想做什么?是的,你可以这样做,但这基本上完全违背了缓存的目的。

    @CacheEvict 默认情况下方法调用之后运行。所以上面的声明的目的是用相同的键缓存列表(因为你的方法没有参数),然后完全清除缓存。

    长话短说:如果你删除这两个注释,你会得到完全相同的结果(除了缓存“emptyListCache”没有被清除)。

    【讨论】:

      猜你喜欢
      • 2018-02-02
      • 1970-01-01
      • 1970-01-01
      • 2018-03-15
      • 1970-01-01
      • 2012-08-20
      • 1970-01-01
      • 2013-07-18
      • 1970-01-01
      相关资源
      最近更新 更多