How to force dispatcher cache urls with get parame

2019-07-21 15:42发布

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.

3条回答
劳资没心,怎么记你
2楼-- · 2019-07-21 16:22

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.

查看更多
Explosion°爆炸
3楼-- · 2019-07-21 16:26

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.

查看更多
姐就是有狂的资本
4楼-- · 2019-07-21 16:35

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.

查看更多
登录 后发表回答