Magnolia 5.6 reached end of life on June 25, 2020. This branch is no longer supported, see End-of-life policy.

Page tree
Skip to end of metadata
Go to start of metadata

Magnolia uses Ehcache for its back-end cache functionality. Ehcache is a robust, proven and full-featured cache product which has made it the most widely-used Java cache.

We recommend you use Ehcache 3 module instead.

Compared with Ehcache 2, the 3.x line brings important changes and improvements such as full compatibility with javax.cache API (JSR-107), off-heap storage capabilities, a revamped API, persistence, improved performance over Ehcache 2.x and much more.


Maven is the easiest way to install the module. Add the following to your bundle:


Pre-built JARs are also available for download. See Installing a module for help.


Ehcache has its own configuration options that can be set in /modules/cache/config/cacheFactory/defaultCacheConfiguration.

You can use a different cache library as long as you implement Java interfaces that allow you to configure caching behavior in the Configuration app. The library can be changed by implementing  Cache  and  CacheFactory . A cache factory is an interface that wraps the functionality and hides the configuration mechanism of the library you choose.

ParameterDefault valueDescription
Instructs Ehcache to wait the specified time in milliseconds before attempting to cache the request. Create the blockingTiemout property in the tree at the same level where the EhCacheFactory class is defined, not inside the defaultCacheConfiguration node.
diskExpiryThreadIntervalSeconds120Number of seconds between runs of the disk expiry thread.
diskSpoolBufferSizeMB30Size to allocate to DiskStore for a spool buffer. Writes are made to this area and then asynchronously written to disk. Default: 30MB. Each spool buffer is used only by its cache. If OutOfMemory errors, you may need to lower this value. To improve DiskStore performance consider increasing it. Trace level logging in the DiskStore will show if put back ups are occurring.
eternaltrueIf elements are set to eternal, timeouts are ignored and the element is never expired.
maxElementsInMemory10000Sets maximum number of objects that will be created in memory. 0 = no limit
maxElementsOnDisk10000000Sets maximum number of objects maintained in the DiskStore. The default value of zero means unlimited.

Policy is enforced upon reaching the maxElementsInMemory limit. Available policies:

  • Least Recently Used (specified as LRU)
  • First In First Out (specified as FIFO)
  • Less Frequently Used (specified as LFU)
overflowToDisktruePermits elements to overflow to disk when the memory store has reached the maxInMemory limit.
timeToIdleSeconds0Optional attribute. Sets max idle time between accesses for an element before it expires. Only used if the element is not eternal. A value of 0 means that an Element can idle indefinitely.
timeToLiveSeconds0Sets lifespan for an element. Only used if the element is not eternal. Optional attribute. A value of 0 means an Element can live for infinity

When using the same webapp with ehcache for both author and public instance

If you are using the same webapp with ehcache for both author and public instance, you must set the property in the file. Make sure to assign different values for the different contexts!


If you do not set the property - the second starting instance will throw an exception: 
net.sf.ehcache.CacheException: net.sf.ehcache:type=CacheManager,name=/path-to-webapp#info.magnolia.module.cache.ehcache.EhCacheFactory#cacheManager