grailsconfigurationehcacheterracotta

Grails local ehcache configured in combination with remote Terracotta


We have ehcache configured in our Grails environment and I'm trying to ascertain how a local cache can be configured with a remote terracotta cache.

The scenario is that we have some data that is minimally expensive to calculate and benefits from a local in-memory cache but the benefit is minimized when using the remote terracotta cache.

The config is currently pretty simple:

<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>

The questions are:

  1. Given the config above, does this imply that a cache put / get will always do a round trip to the terracotta server?

  2. Is there a possible configuration where it will use a local "hot" cache before doing the round trip to the server?

  3. If a local "hot" cache is to be used, this would need to be implemented programmatically using a different cache configuration, not backed by terracotta?

Thanks for any advice ...


Solution

  • A few points:

    Given this, here are the basic operations and their relation to the clustered bit of the cache:

    For these last two operations, the default configuration decouples the local operation from the clustered one. If you cannot handle reading stale value, you can play with the consistency setting.

    This means that answers to your questions are:

    1. See above
    2. Yes
    3. Yes and no: if you need only the local part, you can have a local only cache, just omit the terracotta element in the cache configuration. If you need the clustered bit but want most cache hits to be local hits, you need to tweak your clustered cache configuration.