Does Ehcache Community edition (any version) support disk persistence and recovery after restart?

2,783 views
Skip to first unread message

Mike Morin

unread,
Nov 24, 2014, 11:26:51 AM11/24/14
to ehcach...@googlegroups.com
  1. What version of Ehcache you are currently using; 2.6.3
  2. Paste the configuration for the Cache/CacheManager you have an issue with; (see below)
  3. Add any name and version of other library or framework you use Ehcache with (e.g. Hibernate); none
  4. Providing JDK and OS versions maybe useful as well. jdk 1.6.0_26, Windows 7

This document says persistence is supported for non-enterprise editions of Ehcache versions 2.6+ (see first row of table on page 36): http://ehcache.org/generated/2.9.0/pdf/Ehcache_Configuration_Guide.pdf.

However, I tried using localRestartable but my cahce does not get loaded into CacheManager (I get error"You must use an enterprise version of Ehcache to successfully enable enterprise persistence.")

My config:

    <defaultCache

            maxElementsInMemory="10000"

            eternal="true"

            timeToIdleSeconds="0"

            timeToLiveSeconds="0"

            maxElementsOnDisk="10000000"

            diskExpiryThreadIntervalSeconds="120"

            memoryStoreEvictionPolicy="LRU" >

        <persistence strategy="localRestartable" synchronousWrites="true"/>

    </defaultCache>

This error agrees with what I see in the code - net.sf.ehcache.Cache:

                    if (persistence != null && Strategy.LOCALRESTARTABLE.equals(persistence.getStrategy())) {

                        throw new CacheException("Cache " + configuration.getName()

                                + " cannot be configured because the enterprise features manager could not be found. "

                                + "You must use an enterprise version of Ehcache to successfully enable enterprise persistence.");


So, does the non-enterprise Ehcahce edition support disk persistence and recovery after restart?


Thanks in advance for any help.

Louis Jacomet

unread,
Nov 24, 2014, 12:05:28 PM11/24/14
to ehcach...@googlegroups.com
Hi Mike,

You need to use the legacy configuration options: overflowToDisk="true" and diskPersistent="true" (and remove that persistence tag).

Note that OSS persistence is not fault tolerant and requires proper shutdown of the CacheManager, otherwise it will refuse to load the data from disk.

Regards,
Louis

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.
To post to this group, send email to ehcach...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/dbdacd75-e961-4f9a-8788-022b99c446a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mike Morin

unread,
Nov 25, 2014, 11:44:52 AM11/25/14
to ehcach...@googlegroups.com
Thanks Louis. This worked but only after I added the cache creation to the ehcache.xml config file (instead of doing it programatically). I got the idea from this other thread: http://stackoverflow.com/questions/1729605/ehcache-persist-to-disk-issues.

Thanks again for your help,
Mike

Steven Op

unread,
Oct 19, 2015, 10:18:24 AM10/19/15
to ehcache-users
Hi Louis,

Is there any other way to persist data on disk without properly shut down cache manager (EhCache 2.10.0). Shutting down the cache manager is not  always possible for two main reasons: (i) There could be unplanned shutdown and no one would expect the data to be lost, and (ii) I have defined two caches in ehcache.xml file, one which only requires memory and the other which persist data on it. If I shutdown the cache manager to persist data on disk, the cache manager gets also shut down for the other cache, which means that the new instance of the cache manager is requires and all the data which is stored in the memory cache is gone.

Would be cool if you have an alternative for that?

Many thanks, 

Alex Snaps

unread,
Oct 19, 2015, 10:58:56 AM10/19/15
to ehcache-users
Why not simply use a dedicated CacheManager for the persistent caches and manage its lifecycle accordingly? 
As of today, there is (and never was) a safe way (i.e. crash tolerant) to persist data from a Cache with Ehcache's OS offering. Splitting Caches across CacheManager would solve the second problem, but would leave the "crash" of the JVM aspect unaddressed.   

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.
To post to this group, send email to ehcach...@googlegroups.com.

Louis Jacomet

unread,
Oct 19, 2015, 12:11:08 PM10/19/15
to ehcache-users
Hey,

I want to clarify a few things here:
  • Ehcache will regularly persist all data to disk, especially as the tiering model since at least 2.6 forces all entries to be in the disk tier.
  • If you need to give hints to the cache so that content gets written, you can always call Ehcache.flush(), but even this is async
  • And once again, the Ehcache OS disk store is NOT crash proof, you will need a clean shutdown of the CacheManager if you want to reload the data after a JVM restart.
Nothing that is said above should require you to "close" the CacheManager while your application is operating.

If you find yourself needing a guaranteed durability, you are on a path away from a cache use case into a store - system of record one.

Regards,
Louis

Reply all
Reply to author
Forward
0 new messages