Change persistence strategy of Ehcache in play application

933 views Asked by At

My Goal: I want to configure ehcache to use the hard drive for caching. Ideally cache content will survive application restarts.

Context: play 2.2 application with play-cache_2.10-2.2.2.jar and ehcache-core-2.6.6.jar on classpath

Try: I haven't tried too much yet, because the first attempt indicates that I'm missing something fundamentally.

I just created a ehcache.xml file under app/conf

<ehcache>
    <diskStore path="/var/myapp/persistent/cache>
    <defaultCache 
         maxBytesLocalHeap="512M" 
         eternal="false"
         timeToIdleSeconds="90000" 
         timeToLiveSeconds="0" 
         maxBytesLocalDisk="10G"
         diskExpiryThreadIntervalSeconds="120"
         memoryStoreEvictionPolicy="LFU">

        <persistence strategy="localRestartable" />

    </defaultCache>
</ehcache>

Complains:

net.sf.ehcache.config.InvalidConfigurationException: 
Cannot use localRestartable persistence and disk overflow in the same cache
...
net.sf.ehcache.CacheManager.addCache(CacheManager.java:1177)

 play.api.cache.EhCachePlugin.cache$lzycompute(Cache.scala:143)

 play.api.cache.EhCachePlugin.cache(Cache.scala:142)

 play.api.cache.EhCachePlugin.onStart(Cache.scala:159)
...

Question: How can I change persistence strategy to something different than disk overflow? How can I configure ehcache to use the hard drive for caching?

1

There are 1 answers

0
ARau On BEST ANSWER

According to the EhCache documentation here

• “localRestartable” — Enables the RestartStore and copies all cache entries (on-heap and/or off-heap) to disk. This option provides fast restartability with fault tolerant cache persistence on disk. This option is available for BigMemory Go only.

The BigMemory Go is a paid product from Terracotta which is not open source. This maybe why you are getting the error.