Expand my Community achievements bar.

SOLVED

diaptcher and custom sling servlets

Avatar

Level 4

Hi,

If I have a custom sling servlet for pulling back dynamic content how does that work with the dispatcher eg around caching and invalidation.

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 8

As to the question around caching and invalidation Dispatcher really doesn't support the user case in question out of the box. In order to arrive a solution you'll have to gather a few requirements around your solution:

  1. How are you structuring the URLs of your servlets. If you are using a query string to pass queries or record IDs then by default dispatcher won't be caching the output. You can configure dispatcher to ignore query strings, but then you'd only get one version of the page cached and no matter what query string was sent back you'd have end up with the same cached response. So that means if you want to use dispatcher to cache the responses you will have to find another way to pass back the query string information (generally as a selector, however there are other options). You could also use mod_rewrite to convert the query string to a selector if you wanted end users to see query strings. 
  2. If you do decide to make your URL's dispatcher friendly then you have ask how often does the data change, and how will you be notified of the changes. So will the source system of the dynamic data alert you of a change, will that alert be for a specific. These question will inform your decision - will be flushing items as they change, or will you have to settle for a TTL type of option.
  3. If you can get notifications from the source about when data changes, then you could write a web service that listens for those notifications, and then when it receives a notification you could generate a flush request for the URL in question and send it to dispatcher. See the How do I delete files form cache question on this FAQ page - http://helpx.adobe.com/experience-manager/using/dispatcher-faq.html.
  4. If you need to do a TTL sort of solution then you need to look at writing shell scripts that either delete files on some periodic basis from the cache root, or take a look at leveraging the .stat file and auto-invalidation to achieve your goal. You can check out this page (https://dev.day.com/docs/en/cq/current/deploying/dispatcher.html) for details on how auto-invalidation and the stat file.   

View solution in original post

2 Replies

Avatar

Correct answer by
Level 8

As to the question around caching and invalidation Dispatcher really doesn't support the user case in question out of the box. In order to arrive a solution you'll have to gather a few requirements around your solution:

  1. How are you structuring the URLs of your servlets. If you are using a query string to pass queries or record IDs then by default dispatcher won't be caching the output. You can configure dispatcher to ignore query strings, but then you'd only get one version of the page cached and no matter what query string was sent back you'd have end up with the same cached response. So that means if you want to use dispatcher to cache the responses you will have to find another way to pass back the query string information (generally as a selector, however there are other options). You could also use mod_rewrite to convert the query string to a selector if you wanted end users to see query strings. 
  2. If you do decide to make your URL's dispatcher friendly then you have ask how often does the data change, and how will you be notified of the changes. So will the source system of the dynamic data alert you of a change, will that alert be for a specific. These question will inform your decision - will be flushing items as they change, or will you have to settle for a TTL type of option.
  3. If you can get notifications from the source about when data changes, then you could write a web service that listens for those notifications, and then when it receives a notification you could generate a flush request for the URL in question and send it to dispatcher. See the How do I delete files form cache question on this FAQ page - http://helpx.adobe.com/experience-manager/using/dispatcher-faq.html.
  4. If you need to do a TTL sort of solution then you need to look at writing shell scripts that either delete files on some periodic basis from the cache root, or take a look at leveraging the .stat file and auto-invalidation to achieve your goal. You can check out this page (https://dev.day.com/docs/en/cq/current/deploying/dispatcher.html) for details on how auto-invalidation and the stat file.