3

As I understood after reading these links:

How to find out what does dispatcher cache?

http://docs.adobe.com/docs/en/dispatcher.html

The Dispatcher always requests the document directly from the AEM instance in the following cases:

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, which 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)

But I want to cache url with parameters.

If I once request myUrl/?p1=1&p2=2&p3=3

then next request to myUrl/?p1=1&p2=2&p3=3 must be served from dispatcher cache, but myUrl/?p1=1&p2=2&p3=3&newParam=newValue should served by CQ for the first time and from dispatcher cache for subsequent requests.

Community
  • 1
  • 1
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

3 Answers3

3

I think the config /ignoreUrlParams is what you are looking for. It can be used to white list the query parameters which are used to determine whether a page is cached / delivered from cache or not.

Check http://docs.adobe.com/docs/en/dispatcher/disp-config.html#Ignoring%20URL%20Parameters for details.

Maverick
  • 544
  • 3
  • 14
Markus Haack
  • 103
  • 1
  • 1
  • 7
1

It's not possible to cache the requests that contain query string. Such calls are considered dynamic therefore it should not be expected to cache them.

On the other hand, if you are certain that such request should be cached cause your application/feature is query driven you can work on it this way.

  1. Add Apache rewrite rule that will move the query string of given parameter to selector
  2. (optional) Add a CQ filter that will recognize the selector and move it back to query string

The selector can be constructed in a way: key_value but that puts some constraints on what could be passed here.

Mateusz Chromiński
  • 2,742
  • 4
  • 28
  • 45
  • could you provide example? – gstackoverflow Dec 04 '14 at 11:47
  • I think the suffix would be a better choice. – Tomek Rękawek Dec 04 '14 at 12:22
  • @Tomek Rękawek can you provide more details? if I change URL - then this url will request another resource. can you explain hoe to resolve this problem? – gstackoverflow Dec 04 '14 at 12:27
  • https://forums.adobe.com/message/4930557#4930557 Does this topic relevant for me? – gstackoverflow Dec 04 '14 at 12:57
  • will **myurl.jsp/parameter/values** cache on dispatcher ? – gstackoverflow Dec 05 '14 at 11:31
  • "_Such calls are considered dynamic therefore it should not be expected to cache them._" It's entirely fair to expect to be able to cache requests with query parameters - browsers, CDNs, edge side caches all do it fine. I imagine the actual reason is that the dispatcher's caching is just based on static files on disk, and making the query params part of the filename on disk is awkward. The same reason it can't cache response headers. – Adrian Baker Mar 06 '17 at 01:20
  • You are right, there are ways to cache dynamic data and they also exist in AEM world. I do not agree the root cause of dispatcher not caching query params is the technical limitation of static file naming. Query params are heavily overused in web world. I believe this is a rational decision not to cache query params to ensure (or even enforce) better application architecture i.e. more aligned to Apache Sling principles. As per headers - starting from dispatcher 4.1.11 it's actually feasible. See https://www.cognifide.com/our-blogs/cq/aem-dispatcher-new-features – Mateusz Chromiński Mar 15 '17 at 19:59
1

You can do this with Apache rewrites BUT it would not be ideal practice. You'll be breaking the pattern that AEM uses.

Instead, use selectors and extensions. E.g. instead of server.com/mypage.html?somevalue=true, use: server.com/mypage.myvalue-true.html

Most things you will need to do that would ever get cached will work this way just fine. If you give me more details about your requirements and what you are trying to achieve, I can help you perfect the solution.

Brenn
  • 1,364
  • 1
  • 12
  • 22
  • will **myurl.jsp/parameter/values** cache on dispatcher ? – gstackoverflow Dec 05 '14 at 11:31
  • yes. provided two things: you don't add a query string AND you are always hitting that path with a GET request. Dispatcher doesn't cache things that have a query string (like you used before) or anything that isn't GET, so POST requests, HEAD requests, etc, get forwarded to CQ/AEM – Brenn Dec 05 '14 at 15:27
  • @gstackoverflow I just saw the myurl.jsp - this is wrong. It should be myurl.html Look at how sling selects the script to run. Chances are you want .html as your extension, unless you want the output in some other format (json) and you have a json.jsp script in your components. – Brenn Dec 05 '14 at 18:08