Product Documentation : Ehcache Configuration Guide : Configuring Restartability and Persistence : Configuration Examples
Configuration Examples
This section presents possible disk usage configurations for open-source Ehcache 2.6 and higher.
Temporary Disk Storage
The "localTempSwap" persistence strategy allows the cache to use the local disk during cache operation. The disk storage is temporary and is cleared after a restart.
<diskStore path="/auto/default/path"/>
<persistence strategy=”localTempSwap”/>
With the "localTempSwap" strategy, you can use maxEntriesLocalDisk or maxBytesLocalDisk at either the Cache or CacheManager level to control the size of the disk tier.
In-memory Only Cache
When the persistence strategy is "none", all cache stays in memory (with no overflow to disk nor persistence on disk).
<persistence strategy=”none”/>
Programmatic Configuration Example
The following is an example of how to programmatically configure cache persistence on disk:
Configuration cacheManagerConfig = new Configuration()
.diskStore(new DiskStoreConfiguration()
CacheConfiguration cacheConfig = new CacheConfiguration()
.maxBytesLocalHeap(16, MemoryUnit.MEGABYTES)
     .persistence(new PersistenceConfiguration()
CacheManager cacheManager = new CacheManager(cacheManagerConfig);
Ehcache myCache = cacheManager.getEhcache("my-cache");
Copyright © 2010-2015 Software AG, Darmstadt, Germany.

Product Logo |   Feedback