Dispatcher Configuration to Cache Servlet Requests

Avatar

Avatar
Give Back 5
Level 2
pavanr6387218
Level 2

Like

1 like

Total Posts

11 posts

Correct reply

0 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 3
Ignite 1
View profile

Avatar
Give Back 5
Level 2
pavanr6387218
Level 2

Like

1 like

Total Posts

11 posts

Correct reply

0 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 3
Ignite 1
View profile
pavanr6387218
Level 2

15-05-2018

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" }
  }

Replies

Avatar

Avatar
Give Back 5
Employee
Andrew_Khoury
Employee

Likes

75 likes

Total Posts

93 posts

Correct reply

33 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 10
Give Back
Boost 50
View profile

Avatar
Give Back 5
Employee
Andrew_Khoury
Employee

Likes

75 likes

Total Posts

93 posts

Correct reply

33 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 10
Give Back
Boost 50
View profile
Andrew_Khoury
Employee

15-05-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.

Avatar

Avatar
Give Back 5
Employee
Andrew_Khoury
Employee

Likes

75 likes

Total Posts

93 posts

Correct reply

33 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 10
Give Back
Boost 50
View profile

Avatar
Give Back 5
Employee
Andrew_Khoury
Employee

Likes

75 likes

Total Posts

93 posts

Correct reply

33 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 10
Give Back
Boost 50
View profile
Andrew_Khoury
Employee

15-05-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

Avatar

Avatar
Validate 1
Level 2
VitthalaShiva
Level 2

Likes

5 likes

Total Posts

14 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Give Back 3
Give Back
Boost 5
Boost 3
View profile

Avatar
Validate 1
Level 2
VitthalaShiva
Level 2

Likes

5 likes

Total Posts

14 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Give Back 3
Give Back
Boost 5
Boost 3
View profile
VitthalaShiva
Level 2

15-05-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.

Avatar

Avatar
Ignite 1
Level 1
pavankumarn993
Level 1

Likes

0 likes

Total Posts

7 posts

Correct reply

0 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back
View profile

Avatar
Ignite 1
Level 1
pavankumarn993
Level 1

Likes

0 likes

Total Posts

7 posts

Correct reply

0 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back
View profile
pavankumarn993
Level 1

15-05-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.

Avatar

Avatar
Give Back 5
Level 2
pavanr6387218
Level 2

Like

1 like

Total Posts

11 posts

Correct reply

0 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 3
Ignite 1
View profile

Avatar
Give Back 5
Level 2
pavanr6387218
Level 2

Like

1 like

Total Posts

11 posts

Correct reply

0 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 3
Ignite 1
View profile
pavanr6387218
Level 2

17-05-2018

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

Avatar

Avatar
Give Back 5
Level 2
pavanr6387218
Level 2

Like

1 like

Total Posts

11 posts

Correct reply

0 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 3
Ignite 1
View profile

Avatar
Give Back 5
Level 2
pavanr6387218
Level 2

Like

1 like

Total Posts

11 posts

Correct reply

0 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 3
Ignite 1
View profile
pavanr6387218
Level 2

17-05-2018

I will try implementing resourcemapping and validate if dispatcher caches the request.

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,409 likes

Total Posts

12,671 posts

Correct reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,409 likes

Total Posts

12,671 posts

Correct reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

17-05-2018

Just a general question here - does your servlet return static values. If it returns dynamic values that change each time (ie - return weather data that changes) - why would you cache it?

Avatar

Avatar
Give Back 5
Level 2
pavanr6387218
Level 2

Like

1 like

Total Posts

11 posts

Correct reply

0 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 3
Ignite 1
View profile

Avatar
Give Back 5
Level 2
pavanr6387218
Level 2

Like

1 like

Total Posts

11 posts

Correct reply

0 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back
Ignite 3
Ignite 1
View profile
pavanr6387218
Level 2

17-05-2018

We are fetching articles from 3rd party system via REST API calls. The frequency of this content getting modified is very less. Within AEM, content author would then author the component with the Article API call. This API is forwarded to dispatcher as apiurl in below url.

/bin/servletpathaname/apiurl/a.html. We have a rewrite rule at dispatcher to send the servlet as /bin/servletpathname?queryParam=apiurl. Servlet would then make the call to thirdparty system( we are trying to minimize these calls)

When an enduser hits the page, if we have the servlet response cached we can render that from dispatcher instead of hitting third party system( they have concerns over the traffic to their system).

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,409 likes

Total Posts

12,671 posts

Correct reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,409 likes

Total Posts

12,671 posts

Correct reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

17-05-2018

If the Data changes from the Servlet - will the data be updated in the component or will old cached data still be displayed?  Is that a concern here?