Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set persistence strategy to "localTempSwap" in EHCache 3.x

In EHCache 3.1.3 The 2.x API to set the persistence strategy is missing, for instance the enum net.sf.ehcache.config.PersistenceConfiguration.Strategy is no longer in the lib.

I've read the docs (for version 3.1). but I couldn't find anything about how to configure the persistence strategy, so I suppose that in version 3.x is a different concept or maybe the feature has been removed, but It sounds a bit odd.

Can anyone tell me how can I to configure the EHCache 3.1.x to manage the persistence like Strategy.LOCALTEMPSWAP ? If It's not possible, Is there any alternative or workaround ?

like image 470
Roberto Avatar asked Oct 14 '16 17:10

Roberto


1 Answers

When configuring the disk tier in Ehcache 3.x there is a boolean value that indicates persistence:

  • true: data will be preserved between JVM restarts if the CacheManager or UserManagedCache has been shut down properly using one of the close methods,
  • false: data will not be preserved between JVM restarts although the disk is used during cache operations. Note that this is the default.

Usage depends on where your configuration is sourced from:

  • In Java use ResourcePoolsBuilder.disk(long size, MemoryUnit unit, boolean persistent) with the boolean as defined above,
  • In XML use <ehcache:disk unit="GB" persistent="true">100</ehcache:disk> with the boolean flag again as defined above.

So in order to achieve the equivalent of Strategy.LOCALTEMPSWAP in 2.x you just can work with the default.

Note that as of 3.1.3 you can use a system property in the XML to configure the data folder location as in ${java.tmp.dir}.

like image 55
Louis Jacomet Avatar answered Sep 30 '22 11:09

Louis Jacomet