AEM with Ehcache.

This blog explains the steps required to setup EhCache in AEM. AEM based CMS applications leverage caching at one of the following layers.


AEM instance can take advantage of Content Delivery Networks (CDN) to cache all the static content be its HTML pages, images or Videos. Once a static content gets published via the Content Delivery Network, it gets cached on the CDN for a particular duration. For, e.g., Fastly, Akamai


Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. Varnish Cache is fast. It sits between CDN and Application Server and boost performance with its in-memory accelerator anywhere between 5x-10x over using Apache. It gives an additional check on Dos Attacks and can help to avoid Dog-pile effect when CDN cache gets invalidated.

Dispatcher Cache

AEM dispatcher module can be installed on the Apache HTTP server. It acts as a reverse proxy with a local disk cache. It supports event based cache eviction and authoring, or the publishing instances can send events of deleting and invalidating cache files on these servers.

Application Cache

AEM Application Cache is the last layer in the AEM Caching strategy. It's quite useful in the personalization services, where many components need a real-time business computation before getting rendered and cannot be cached in above three caching layers.

There are various options to facilitate in-memory Application caching using Redis, EhCache or MemCache. Although it's standard practice in AEM space, I haven’t seen any quick step documentation. Hence, I thought to put them in a blog using ehCache. It can be easily modified to work with other caching implementations.

1. Maven (pom.xml)

Make sure to use the updated version of the jars.

Also, append the Ehcache in the Embed-Dependency in case you are using maven-bundle-plugin configuration.

2. ehCache configuration (ehCache.xml)

3. Cache service implementation

4. Sample Service Component

5. Configure as JMX Bean

6. Cache Flush Configuration

  • Go to '/system/console/jmx'
  • A table with 4 columns will show up (Domain, Name, Type, Properties).
  • Look up for all entries with Domain: net.sf.ehcache and Type: cache

  • Click on the cache you want to clean, e.g. cacheTag
  • You will see a page similar to this one:

  • Click on "removeAll" and then on "Invoke".