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
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Avoid caching URLs with query paramters

v1101
Level 5
Level 5

Hello Community - I have a page with dynamic content. Based on the results from the below URLs(with query string), the content is getting displayed on the page (www.test.com/products.html) and it is working fine in author, publish and dispatcher.

 

https://www.test.com/pages/_jcr_content.product.json?t=2011233&Tags=abc&Order=existing

https://www.test.com/pages/_jcr_content.product.json?t=2034567&Tags=def&Order=existing

https://www.test.com/pages/_jcr_content.product.json?t=2912345&Tags=ghi&Order=existing

https://www.test.com/pages/_jcr_content.product.json?t=2983456&Tags=jkl&Order=existing

 

If I directly access the page (CDN), the URL with query parameter is getting cached,  i.e., I see the same content for all four sections of the page. We need to restrict the URLs with the query parameters to be cached, the results should display different results as the query parameters are different and it should not be cached.

 

https://www.test.com/pages/_jcr_content.product.json?t=2983456&Tags=jkl&Order=existing

https://www.test.com/pages/_jcr_content.product.json?t=2983456&Tags=jkl&Order=existing

https://www.test.com/pages/_jcr_content.product.json?t=2983456&Tags=jkl&Order=existing

https://www.test.com/pages/_jcr_content.product.json?t=2983456&Tags=jkl&Order=existing

1 Accepted Solution
snbaem
Correct answer by
Community Advisor
Community Advisor

As mentioned above by @Manjunath_K there should be a setting in CDN. For example see - https://docs.microsoft.com/en-us/azure/cdn/cdn-query-string

Just putting out an after thought though 🙂  - If this is an external facing page and with considerably high number of products, the query parameters could be passed as post data form parameters via ajax call and allow caching of the calls and clear the cache using TTL in Dispatcher and CDN (or custom implementation to clear it) in case of any performance concerns

View solution in original post

6 Replies
Manjunath_K
Community Advisor
Community Advisor

Hi @v1101,

Check if ignore query string is enabled at CDN caching level, this might be the reason these JSON response are not getting cached when its accessed using dispatcher url & getting cached when its accessed using CDN website url. another option is, you can set below mentioned response header in backend servlet so that this response will not cached.

 

response.addHeader("Cache-Control","no-store no-cache");

 

v1101
Level 5
Level 5

Thanks @Manjunath_K for the response. Will check the config in CDN level. In my case, the call to the servlet is having the same URL(with query string) and that is the reason I am seeing the same content. I don't think setting the option in servlet (response,addHeader) will solve my issue.

Manjunath_K
Community Advisor
Community Advisor

Hi @v1101 

Though call to the servlet is having the same URL(with query string), adding below header in response header will make sure the particular response is not stored in any cache. but normally will go with this setting response header approach when we have some performance use case where we need cache some request & some request should not be cached. so, first check if ignore query string enabled at CDN caching level & if still root cause not found setting this response header will be alternate approach.

 

response.addHeader("Cache-Control","no-store no-cache");

 

 

prashantonkar
Level 4
Level 4
Can you elaborate how this calls are being made from your html? Are you making AJAX calls?
snbaem
Correct answer by
Community Advisor
Community Advisor

As mentioned above by @Manjunath_K there should be a setting in CDN. For example see - https://docs.microsoft.com/en-us/azure/cdn/cdn-query-string

Just putting out an after thought though 🙂  - If this is an external facing page and with considerably high number of products, the query parameters could be passed as post data form parameters via ajax call and allow caching of the calls and clear the cache using TTL in Dispatcher and CDN (or custom implementation to clear it) in case of any performance concerns

View solution in original post