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.

Installing

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

Error rendering macro 'artifact-maven-dependencies-snippet-macro'

com.sun.jersey.api.client.ClientHandlerException: java.net.NoRouteToHostException: No route to host (Host unreachable)

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

  • Error rendering macro 'artifact-resource-macro'

    com.sun.jersey.api.client.ClientHandlerException: java.net.NoRouteToHostException: No route to host (Host unreachable)

Usage

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 

$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources") Cache
 and 
$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources") CacheFactory
. A cache factory is an interface that wraps the functionality and hides the configuration mechanism of the library you choose.

ParameterDefault valueDescription
blockingTimeout10000
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
$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources") 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.
memoryStoreEvictionPolicyLRU

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 magnolia.cache.manager.id in the magnolia.properties file. Make sure to assign different values for the different contexts!

webapp/WEB-INF/config/magnoliaAuthor/magnolia.properties
magnolia.cache.manager.id=cache-on-author 
webapp/WEB-INF/config/magnoliaPublic/magnolia.properties
magnolia.cache.manager.id=cache-on-public 

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

#trackbackRdf ($trackbackUtils.getContentIdentifier($page) $page.title $trackbackUtils.getPingUrl($page))