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:
Given the config above, does this imply that a cache put / get will always do a round trip to the terracotta server?
Is there a possible configuration where it will use a local "hot" cache before doing the round trip to the server?
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 ...
A few points:
maxElementsInMemory
will apply to a on-heap tier of the cache, local to each JVM part of the Terracotta cluster. Note: maxElementsInMemory
is deprecated and should be replaced by maxEntriesLocalHeap
in recent Ehcache versions.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:
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.