【问题标题】:spring ehcache integration with self-populating-cache-scopespring ehcache 与自填充缓存范围的集成
【发布时间】:2012-04-24 17:19:30
【问题描述】:

我必须整合spring和ehcache,并尝试用blockingCache模式实现它

<ehcache:annotation-driven/>

对于共享(默认)和方法self-populating-cache-scope 有一个选项。你能解释一下有什么区别吗?

还有带有 selfPopulating 标志的注解 @Cacheable

根据我在某些帖子上看到的内容

http://groups.google.com/group/ehcache-spring-annotations/browse_thread/thread/7dbc71ce34f6ee19/b057610167dfb815?lnk=raot

它说何时使用 shared 只创建一个实例,并且每次使用相同的缓存名称时都会使用相同的实例,所以如果我使用 selfPopulating 将一种方法标记为 true,

所有试图访问其他方法的线程都用注释 @Cacheable 将 selfPopulating 标志设置为 true 将继续暂停 我不要

<ehcache:annotation-driven/>

另一方面,当 self-populating-cache-scope = method 为所有使用 @Cacheable 注释的方法创建 单独的实例 时,selfPopulating 标志设置为 true,因此它不会不会造成问题。

但是在这种情况下,当我尝试使用 @TriggerRemove 删除一个元素并提供 @Cacheable 中使用的缓存名称时,它会在每个单独的实例中搜索以找到该值吗?这不是开销吗?

【问题讨论】:

    标签: ehcache


    【解决方案1】:

    由 Eric 在上面的 ehcache google 小组中回答

    在所有情况下,都有一个底层 Ehcache 实例。发生什么了 当您设置 selfPopulating=true 时,SelfPopulatingCache 包装器是 已创建。

    如果 cache-scope=shared 则所有使用该命名缓存的注解将 使用相同的 SelfPopulatingCache 包装器 If cache-scope=method then 每个方法创建一个包装器

    注意在这两种情况下 SelfPopulatingCache 都是一个包装器,有 仍然只有一个实际的缓存支持包装器

    至于阻塞,如果您阅读 SelfPopulatingCache 的文档和 BlockingCache 你会注意到 ehcache 在 通过键条带化缓存级别锁定和每个键锁定。 http://ehcache.org/apidocs/net/sf/ehcache/constructs/blocking/BlockingCache.html

    【讨论】:

      猜你喜欢
      • 2012-06-27
      • 2012-01-03
      • 2012-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-28
      • 1970-01-01
      相关资源
      最近更新 更多