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

Cache servlet response

Avatar

Level 5

I had assumed I could cache the response from a servlet in AEM but at the moment this does not seem to be the case. The url for my servlet is: /some/url.param1.param2.json I thought because I am using selectors the dispatcher would be happy to cache it but this is not the case. If I change a node manually in CRX I see this change reflected in the JSON I get back from the servlet showing that the dispatcher is not caching this at all.

Is it possible to cache a servlet? If so could there be some config on the dispatcher I need to do, no other urls currently go via /ajax, we have configured our IHS server to pass these requests to AEM but perhaps I need to make a change on the dispatcher? 

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Did you add the caching rule for this URL in the dispatcher configuration file ?

Please see the following doc -  https://docs.adobe.com/docs/en/dispatcher/disp-config.html#par_146_44_0010

SPECIFYING THE DOCUMENTS TO CACHE

The /rules property controls which documents are cached according to the document path. Regardless of the /rules property, Dispatcher never caches a document in the following circumstances:

  • If the HTTP method is not GET.
    Other common methods are POST for form data and HEAD for the HTTP header.
  • If the request URI contains a question mark ("?").
    This usually indicates a dynamic page, such as a search result that does not need to be cached.
  • The file extension is missing.
    The web server needs the extension to determine the document type (the MIME-type).
  • The authentication header is set (this can be configured)

Each item in the /rules property includes a glob pattern and a type:

  • The glob pattern is used to match the path of the document.
  • The type indicates whether to cache the documents  that match the glob pattern. The value can be either allow (to cache the document) or deny (to always render the document).  

If you do not have dynamic pages (beyond those already excluded by the above rules), you can configure Dispatcher to cache everything. The rules section for this looks as follows:

     
1
2
3
4
/rules
  {
    /0000  {  /glob "*"   /type "allow" }

View solution in original post

2 Replies

Avatar

Correct answer by
Employee Advisor

Did you add the caching rule for this URL in the dispatcher configuration file ?

Please see the following doc -  https://docs.adobe.com/docs/en/dispatcher/disp-config.html#par_146_44_0010

SPECIFYING THE DOCUMENTS TO CACHE

The /rules property controls which documents are cached according to the document path. Regardless of the /rules property, Dispatcher never caches a document in the following circumstances:

  • If the HTTP method is not GET.
    Other common methods are POST for form data and HEAD for the HTTP header.
  • If the request URI contains a question mark ("?").
    This usually indicates a dynamic page, such as a search result that does not need to be cached.
  • The file extension is missing.
    The web server needs the extension to determine the document type (the MIME-type).
  • The authentication header is set (this can be configured)

Each item in the /rules property includes a glob pattern and a type:

  • The glob pattern is used to match the path of the document.
  • The type indicates whether to cache the documents  that match the glob pattern. The value can be either allow (to cache the document) or deny (to always render the document).  

If you do not have dynamic pages (beyond those already excluded by the above rules), you can configure Dispatcher to cache everything. The rules section for this looks as follows:

     
1
2
3
4
/rules
  {
    /0000  {  /glob "*"   /type "allow" }