Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Does AEM have any sort of distributed caching which can be used?

Avatar

Level 9

Using querybuilder to retrieve pages and components to build json responses in servlets is very slow (seconds).  The obvious solution is for us to cache all the required pages components properties, and just read off the required page properties from cache.  Usually you would use distributed memory cache such as memcached, or an external cache such as redis.

Does AEM have anything like this out of the box?

If we setup memcached, presumably it will have to one perinstance, and not distributed.  This will make manual flushing difficult.  If we use external cache, such as redis, then this will be slower as we cant host redis in the same DC as AEM cloud (As we don't know here they are hosted) so latency will again be an issue.

Any suggestions?

The use case is recent / favourite games.  If we have say 500 game pages, each with several components with properties such as category, image, description etc.  We would get a list of recent game IDs from the server, then need to lookup up each page with the correspoding game ID or code, then look up the required components on that page, in order to display thumbnails and short text etc.  Given the slow speed of querybuilder, we could cache the pages and their properties in memory for quick lookup, and then refresh the pages every 5 minutes or similar in case they get edited by content editor (a flush feature would be nice, but would have to flush all cloud instances which is presumably hard)

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @TB3dock 

 

You can try for EhCache which caches the object at the JVM level. Please see more details below:

https://www.ehcache.org/documentation/2.8/code-samples.html

http://blog.atish.me/2016/12/25/AEM-Ehcache/

 

Thanks!

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @TB3dock 

 

You can try for EhCache which caches the object at the JVM level. Please see more details below:

https://www.ehcache.org/documentation/2.8/code-samples.html

http://blog.atish.me/2016/12/25/AEM-Ehcache/

 

Thanks!

Avatar

Employee Advisor

Hi @TB3dock!

I'm not sure if I understand your use case 100% correct.

I'll just leave some general advice with regards to caching.

When working with AEM, you can leverage several levels of caching:

  • Browser caching (setting according headers on your HTTP response)
    Usually, this can be applied best for long living resources, such as JS and CSS files or certain images (e. g. a logo). But with shorter TTLs (time to live), this can also be leveraged for HTML pages or other responses (e. g. XHR). General advice is to start with short TTLs and increase them in small and granular steps. If applied correctly, this can boost the performance of your website.
  • CDN Caching
    If you are using a content delivery network (CDN), this gives you another layer of caching. AEMaCS comes with an integrated CDN, so you already have that in place and can evaluate if your application/pages is leveraging it to its optimum.
  • Dispatcher Caching
    For AEM it is always recommended to cache as much as possible on the dispatcher level and design your application to allow for maximum caching. If you are able to cache the requests that lead to long running queries on your publish instances, this will avoid calls to the publisher altogether. If applied correctly (and reflected in the design of the application), you can really cache a lot. It is not uncommon, especially for marketing websites, to achieve caching rations of more than 95%. Of course, this depends on the nature of the website and your application design. Please note that you can not only cache HTML pages, assets, JS and CSS files, but also JSON responses (XHR) and similar requests.
  • In-memory caches
    In addition to the above mentioned layers you can also introduce caching solutions on the AEM layer. A common choice is Ehcache as already mentioned by @Asutosh_Jena_. AFAIK there is no OOTB integration for this layer of caching.

Please also bear in mind that caching is easy but correct cache invalidation is hard (some even say it's impossible).

Hope that helps!

Avatar

Community Advisor

@TB3dock have you thought of using a dedicated search service such as elastic or solr which will give you json output which you can use in any of FE frameworks to render pages on fly..?