Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Dispatcher cache clear strategy for service

Avatar

Level 2

Hi,

 

I have a service rendering at ../../test.xml and it returns some data (according to backend business logic) of the last 10 activated pages of a particular template.

 

Eg. getting details of the last 10 blog articles.

 

What is the best way to cache this service in dispatcher and clear the cache on activation of any page under a particular hierarchy/template type?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
0 Replies

Avatar

Level 9

Hi @VinayHegde 

 

You can try below code in vhost file. You can set the maxage for cache and refresh the data periodically.

<LocationMatch "^/content/.*\.test\.(?i:xml|css|tiff)$">
Header set Cache-Control "max-age=120,s-maxage=0,stale-while-revalidate=43200,stale-if-error=43200" "expr=%{REQUEST_STATUS} < 400"
Header set Age 0
</LocationMatch>

 If you need to clear the cache on page publish you can also do a event handler

Avatar

Correct answer by
Community Advisor

Avatar

Level 7

It would be good if you know when this call gives updated data. If you get updated data every 30 days then cache it on dispatcher.

Below code cache xml calls for 12 hr. Add this code in vhost file.

<LocationMatch "^/content/.*\.test\.(?i:xml)$">
    Header set Cache-Control "max-age=120,s-maxage=0,stale-while-revalidate=43200,stale-if-error=43200" "expr=%{REQUEST_STATUS} < 400"
    Header set Age 0
</LocationMatch>

 

Avatar

Level 2

Thanks, @HeenaMadan, and @Jagadeesh_Prakash for this solution. 
However, I feel the answer by @arunpatidar seems the best fit here.

 

For blogs and all, there will be no specific timeline for the addition of new content. I tried ACS Flush rules. It worked pretty fine, clearing cache only on particular hierarchy activation and it's so simple to implement.

 

Just clear cache as soon as new content comes with no time barrier, so I feel this solution is the best fit here.

 

@kautuk_sahni - Do you think ACS one could be accepted best solution here?