Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to maintain the memory cache in AEM .?

Avatar

Level 4

Hello Team,
Let me try to explain our problem, We have a large number of pages (around 200+ pages) 
and these are all structured pages with some data points. We have an end-user landing page, this page has a couple of filters to filter the results.
As of now we're processing all pages data on an ajax call and returning the data to the browser on page loading.

With this approach, the page is getting timeout errors/slow rendering sometimes.
We've decided to implement the memory cache on publishing nodes and return the cache to the end-user page.

So, What's the best way to flush the cache ? or any better thoughts on this approach.?

 

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi @vmadala!

Caching is a very important topic in the context of AEM. You should always aim to cache as much as possible on all available layers.

Your application architecture and requirement is not 100% clear to me from your explanation but I would definitely look at the following options for caching and performance tuning (probably in this order):

  • Dispatcher caching
    The dispatcher is AEMs central point for caching and it's capable to cache most types of requests, including JSON content and ajax calls. So my first recommendation is to evaluate if you can cache not only your pages, assets and client side code (JS, CSS) but also ajax calls and similar requests on the dispatcher level. 
    Please refer to the official documentation and the optimization guide for more information.
  • Query performance tuning
    As already mentioned in this thread, you may also want to look if you are able to increase the performance of your queries, e. g. by tuning and refactoring them or by backing them up with dedicated index definitions for faster execution. The slow query troubleshooting guide may give you a starting point.
  • In-memory caching
    There are different approaches to in-memory caching for various use cases in AEM. It could definitely be a valid approach to hold query results in memory. Some approaches go even further and hold the resulting rendering in memory. I've seen implementation of ehcache holding components, pages or other artifact in memory and invalidating them automatically on a certain schedule or based on certain events.
  • Client-side/browser caching
    Please also check if certain elements can be cached on the client-side by setting according headers on the response. If the browser doesn't even need to re-request a certain URL, this is the fastest experience that you can get. I recommend to start with rather low TTLs and increase/optimize them slowly. There is no way you can invalidate a client-side cache (apart from maybe changing the URL or similar), so be cautious.

 

Please note: While caching is quite easy, invalidation is hard to get right.

While approaches for invalidation of the dispatcher cache are quite clear in general, the most relevant part is always about your application and content architecture and can hardly be advised without more detailed insights.

 

Hope that helps!

View solution in original post

11 Replies

Avatar

Level 4
Thanks @Bimmi_Soi, The provided link is talk about dispatcher, I want to implement memory cache in AEM publish server.

Avatar

Community Advisor

Hi @vmadala 

   Keeping data in memory cache will surely save unnecessary query on publishers.

In your scenario you can invalidate memory cache receiving node/page activation event.

 

And it is always helpful to create small tool for full cache invalidation where admin/superauthor can invalidate 

Avatar

Level 4
Thanks @Dipti_Chauchan, Is there any way can we handle these events on publish server (not on author).?

Avatar

Community Advisor

@vmadala,

A standard way to serve a secure and fast website experience will be to use the standard AEM dispatcher Apache web server module. 

Checkout this in-depth video to understand exactly what AEM dispatcher is, https://www.youtube.com/watch?v=i5dzqbpCwGk

Avatar

Level 4
Thanks @BrianKasingli, the above topic is talking about dispatcher cacher, but I want memory cache in java.

Avatar

Employee Advisor

@vmadala  What's the format of key-value pair in in-memory cache?

Are you storing the query as the key and its results as the value? You could probably write a servlet and pass the key as an argument to delete.

Also, it would be worth checking if indexing (in case you're using sql/ xpath queries) can be done to improve the performance.

Avatar

Level 3

Hi,

 

Create a collection variable(ideally a Map with page path as key and content as value) as a global variable at a OSGi service. You can clear the data/cache of Map variable in activate/deactivate method or by registering an activation event or by a servlet with specific parameters either to flush entire data or only specific page paths data.

 

Thanks,

Harish.

Avatar

Administrator
@harish_malineni, good to see you helping other AEM users. Keep the great work going.


Kautuk Sahni

Avatar

Correct answer by
Employee Advisor

Hi @vmadala!

Caching is a very important topic in the context of AEM. You should always aim to cache as much as possible on all available layers.

Your application architecture and requirement is not 100% clear to me from your explanation but I would definitely look at the following options for caching and performance tuning (probably in this order):

  • Dispatcher caching
    The dispatcher is AEMs central point for caching and it's capable to cache most types of requests, including JSON content and ajax calls. So my first recommendation is to evaluate if you can cache not only your pages, assets and client side code (JS, CSS) but also ajax calls and similar requests on the dispatcher level. 
    Please refer to the official documentation and the optimization guide for more information.
  • Query performance tuning
    As already mentioned in this thread, you may also want to look if you are able to increase the performance of your queries, e. g. by tuning and refactoring them or by backing them up with dedicated index definitions for faster execution. The slow query troubleshooting guide may give you a starting point.
  • In-memory caching
    There are different approaches to in-memory caching for various use cases in AEM. It could definitely be a valid approach to hold query results in memory. Some approaches go even further and hold the resulting rendering in memory. I've seen implementation of ehcache holding components, pages or other artifact in memory and invalidating them automatically on a certain schedule or based on certain events.
  • Client-side/browser caching
    Please also check if certain elements can be cached on the client-side by setting according headers on the response. If the browser doesn't even need to re-request a certain URL, this is the fastest experience that you can get. I recommend to start with rather low TTLs and increase/optimize them slowly. There is no way you can invalidate a client-side cache (apart from maybe changing the URL or similar), so be cautious.

 

Please note: While caching is quite easy, invalidation is hard to get right.

While approaches for invalidation of the dispatcher cache are quite clear in general, the most relevant part is always about your application and content architecture and can hardly be advised without more detailed insights.

 

Hope that helps!