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.
From Magnolia 5.5.4+, 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 dependency to your bundle:
<dependency> <groupId>info.magnolia.cache</groupId> <artifactId>magnolia-cache-ehcache</artifactId> <version>5.5.9</version> </dependency>
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
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.
Instructs Ehcache to wait the specified time in milliseconds before attempting to cache the request. Create the
|Number of seconds between runs of the disk expiry thread.|
|Size 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.|
|If elements are set to eternal, timeouts are ignored and the element is never expired.|
|Sets maximum number of objects that will be created in memory. |
|Sets 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:
|Permits elements to overflow to disk when the memory store has reached the maxInMemory limit.|
|Optional attribute. Sets max idle time between accesses for an element before it expires. Only used if the element is not eternal. A value of |
|Sets lifespan for an element. Only used if the element is not eternal. Optional attribute. A value of |
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
magnolia.cache.manager.id in the magnolia.properties 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: javax.management.InstanceAlreadyExistsException: net.sf.ehcache:type=CacheManager,name=/path-to-webapp#info.magnolia.module.cache.ehcache.EhCacheFactory#cacheManager