Expand my Community achievements bar.

Dispatcher - Caching 2 copies of the page ?

Avatar

Level 4

Hello All,

         We have a Sling Model which returns true/false based upon, whether the request has a particular cookie or not in it.

The dispatcher caches the first request to the page(which may or may not a have cookie on it). The next time a person requests the page, they will get the first person's response from cache. .

But we want to cache two copies of the page, one for people with the cookie in request , one for without cookie in request

Is it possible to cache like this? or any alternative approach to achieve above scenario?

Thanks in Advance

Sreenivasula Reddy

10 Replies

Avatar

Level 10

I have never read anywhere that Dispatcher caches 2 versions of the same page.

Avatar

Level 4

Thanks Scott!

Is there any alternative approach to handle such situation, where Sling model evaluates to a different value(true/false) based on request (if it has a cookie true, if not false)? And we need to cache, such 2 page variants?

Avatar

Employee Advisor

The dispatcher can only return what is requested. It has no built-in logic to decide if a page has to be returned or a different page.

You can of course 2 versions of that page with different selectors

  • a version for a request with the correct cookie (selector "cookie")
  • a version for a request without that cookie (selector "nocookie")

Then you have 2 pages, but you still need to know upfront, which one you need to display, as you need to create the correct link to it.

Jörg

Avatar

Level 4

Thanks Jorg!

   We have above requirement as part of personalizing the content in AEM 6.0 using client context. Certain segment of users have a cookie in their request, so we have to show personalized content (along with default content for all users) and certain does not have this cookie in their request, so we wont show any personalized content(only default content).

But we want to cache the page for both scenarios( personalized and default). So in the above scenario, how to implement caching ?

thanks in advance

Avatar

Employee Advisor

Render all the content into the very same HTML and hide the personalized part by default? In case the cookie is present make this content visible?

Of course I could imagine more complex scenarios, but this would be a very simple solution.

Jörg

Avatar

Level 4

So you mean you need single personalized page to be served for all the authenticated users?

Avatar

Level 4

Thanks Navin!

Yes its a single page(home page with some default content authored on the page and a teaser component added for personalized content).

Only authenticated users have access to this home page.

When some segment of users (say sales) access the page, they have a cookie in their request,so we have to show both default and personalized content

For rest of the users, who does not have a cookie in their request, we have to show only default content.

So my question is how caching works in the above 2 scenarios ?

Avatar

Level 4

So far i know it cannot be done using simple AEM Dispatcher configuration. You can do a trick using Apache Rewrite module.

1. Keep 2 pages (PageWithCookie & pagewithNoCookie) in AEM, which will be cached in Dispatcher.

2. Evaluate a condition inside that if cookie header is there in request then serve the PageWithCookie else serve pagewithNoCookie.

Hope this would work.

Avatar

Employee Advisor

navinkaushal​ that approach is working, but it does not scale when you need to implement similar logic to other pages as well. Do you want authors to raise a IT ticket to change the dispatcher/webserver config?

Jörg

Avatar

Level 4

Offcourse this cannot be done without help of IT. IT guys can keep a pattern so that this config dont need to get changed again and again.