How to maintain the memory cache in AEM .? | Community
Skip to main content
vmadala
Level 3
Jun 29, 2021 11:51 AM UTC
Solved

How to maintain the memory cache in AEM .?

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.?

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
MarkusBullaAdobe
MarkusBullaAdobeAccepted solution
Employee
Jun 30, 2021 12:33 PM UTC

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!

11 replies

MarkusBullaAdobe
MarkusBullaAdobeAccepted solution
Employee
Jun 30, 2021 12:33 PM UTC

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!

Translate
arunpatidar
New Participant
Jun 30, 2021 9:43 AM UTC
Level 2
Jun 30, 2021 7:09 AM UTC

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.

Translate
kautuk_sahni
Employee
Jul 1, 2021 12:24 PM UTC
@harish_malineni, good to see you helping other AEM users. Keep the great work going.
Translate
Kautuk Sahni
shelly-goel
Employee
Jun 30, 2021 5:35 AM UTC

@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.

Translate
BrianKasingli
New Participant
Jun 29, 2021 10:27 PM UTC

@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

Translate
vmadala
vmadalaAuthor
Level 3
Jun 30, 2021 5:26 AM UTC
Thanks @briankasingli, the above topic is talking about dispatcher cacher, but I want memory cache in java.
Translate
Dipti_Chauhan
New Participant
Jun 29, 2021 2:23 PM UTC

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 

Translate
vmadala
vmadalaAuthor
Level 3
Jun 30, 2021 12:40 AM UTC
Thanks @2251484_Chauchan, Is there any way can we handle these events on publish server (not on author).?
Translate
Employee
Jun 29, 2021 12:18 PM UTC
vmadala
vmadalaAuthor
Level 3
Jun 29, 2021 2:16 PM UTC
Thanks @bimmiso, The provided link is talk about dispatcher, I want to implement memory cache in AEM publish server.
Translate