结合远程 Terracotta 配置的 Grails 本地 ehcache

标签 grails configuration ehcache terracotta

我们在 Grails 环境中配置了 ehcache,我正在尝试确定如何使用远程 terracotta 缓存配置本地缓存。

场景是我们有一些计算成本最低的数据,并且从本地内存缓存中受益,但在使用远程 terracotta 缓存时 yield 最小化。

配置目前非常简单:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" >
  <diskStore path="java.io.tmpdir"/>
  <cacheManagerEventListenerFactory class="" properties=""/>
  <defaultCache
       maxElementsInMemory="20000"
       eternal="false"
       timeToLiveSeconds="12000"
       overflowToDisk="false"
       diskPersistent="false">
    <terracotta />
  </defaultCache>
  <terracottaConfig url="${com.ngs.app.tc.host}:${com.ngs.app.tc.port}" />

  <cache name="org.hibernate.cache.UpdateTimestampsCache"
      maxElementsInMemory="10000"
      timeToIdleSeconds="300"/>

  <cache name="org.hibernate.cache.StandardQueryCache"
      maxElementsInMemory="10000"
      timeToIdleSeconds="300"/>
</ehcache>

问题是:
  • 鉴于上面的配置,这是否意味着缓存 put/get 将始终往返于 terracotta 服务器?
  • 是否有可能的配置在往返服务器之前使用本地“热”缓存?
  • 如果要使用本地“热”缓存,则需要使用不同的缓存配置以编程方式实现,而不是由 terracotta 支持?

  • 感谢您的任何建议...

    最佳答案

    几点:

  • 上面的配置只声明了默认的缓存是集群的,命名的缓存是不集群的。
  • Ehcache 使用分层系统,这意味着即使对于集群缓存,maxElementsInMemory 的设置将应用于缓存的堆上层,在 Terracotta 集群的每个 JVM 部分本地。注:maxElementsInMemory已弃用,应替换为 maxEntriesLocalHeap在最近的 Ehcache 版本中。

  • 鉴于此,以下是基本操作及其与缓存的聚集位的关系:
  • 获得本地热门:仅涉及堆上层,没有 Terracotta 往返
  • Get with a local miss: 将去尝试在集群中寻找值(value) - Terracotta 往返
  • 放:将需要更新集群- Terracotta 往返
  • 删除:将需要更新集群 - Terracotta 往返

  • 对于最后两个操作,默认配置将本地操作与集群操作分离。如果您无法处理读取过时的值,您可以使用 consistency setting .

    这意味着您的问题的答案是:
  • 见上文
  • 是和否:如果您只需要本地部分,您可以有一个仅本地缓存,只需省略 terracotta缓存配置中的元素。如果您需要集群位但希望大多数缓存命中是本地命中,则需要调整集群缓存配置。
  • 关于结合远程 Terracotta 配置的 Grails 本地 ehcache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27538768/

    相关文章:

    java - Spring Cache——无法获取数据列表

    java - 配置 ehCache : Cache is null

    java - 如何从 Grails 中的 Http 响应获取 boolean 值

    list - Grails-在gsp中引用绝对URL

    grails - 如何使用GORM测试实例是否在数据库中持久存在?

    grails - Grails 2.2.5-域对象未保存,但没有错误

    configuration - 如何让Hudson通过代理进行更新

    hibernate - 如何在Grails 3中将属性传递给Enver?

    configuration - hadoop 示例未在亚马逊 ec2 上运行

    java - Spring EhCache 中多个缓存不起作用