Skip to main content
New Participant
May 15, 2018

Dispatcher Configuration to Cache Servlet Requests

  • May 15, 2018
  • 4 replies
  • 8688 views

Hi,

We have a requirement where in  we want to cache the servlet(AEM) response.

Servlet is making a REST call to third party to fetch a response which is constant(response remains same)

Response of the servlet to be cached:

Servlet :  /bin/servletpathname?queryParam=apiurl.

From clientside, we are making an ajax call to /bin/servletpathaname/apiurl/a.html (a.html is being appended so that the request has an extension.).

At Dispatcher We

are using internal redirect to redirect /bin/servletpathaname/apiurl/a.html  to /bin/servletpathname?queryParam=apiurl.

We are able to get a successful response back from servlet (Internal Redirect is successful). But at dispatcher we observe that the request is not getting cached.

Am I missing something?

I want to understand how can we cache the servlet response, this would greatly reduce the load on the end server and improve performance.

Dispatcher:

  • The request is a GET request
  • We have appended extension for the primary request.
  • No Query Param in the initial request
  • There is no authorization.

Dispatcher.any:

/rules
  {
    /0000  {  /glob "*"   /type "allow" }
  }
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

New Participant
December 18, 2018

Is this question answered ? As I am also trying to do something similar however I am trying to cache service response.

URL: domain:port/services/servicename/apiname

This URL is a calls AEM servlet internally using httpclient and bring tons of data in json format, (static data).  Since it is taking a minute or more to return the response, I want to cache it at dispatcher.

How I can proceed with ?

Regards

Vikas

New Participant
January 2, 2023

@pavanr6387218  is it resolved if yes how did you resolve did you replace query param with selectors?

New Participant
May 16, 2018

Hi , Since in your case getting the same response always ,

Instead of using query params, you can also try selectors like /bin/servletpathaname/a.apiurl.html in Ajax call. Later you can read this selector in servlet , by this you can cache the response.

VitthalaShiva
New Participant
May 16, 2018

Can u create a servlet with the resouceType instead of path.

This will help u to cache the request on dispatcher and also just create a nide under /etc whose resource type will be ur servlet.

Let me know if this works.

New Participant
May 17, 2018

Resoruce Type would not be an option as the apiurl will be authored.

akhoury
Employee
May 15, 2018

> At Dispatcher We are using internal redirect to redirect /bin/servletpathaname/apiurl/a.html  to /bin/servletpathname?queryParam=apiurl.

That will not make the request cacheable unfortunately, dispatcher will not cache 301 or 302 redirects or requests that it must send with a querystring.  Even though you are rewriting this or redirecting this at the Apache level you cannot cache it in dispatcher unless you create a mapping in AEM that maps from /bin/servletpathaname/apiurl/a.html  to /bin/servletpathname?queryParam=apiurl.  Alternatively, you could cache these requests at the CDN level.  Many CDNs do allow caching of requests with querystrings.

akhoury
Employee
May 15, 2018

Note: The request received by Apache here is the /bin/servletpathaname/apiurl/a.html one, but the request being received and sent by the dispatcher module within apache has the querystring: /bin/servletpathname?queryParam=apiurl