Set Response Cache-Control on Staled Content

#1
I want all requests to use both cache (application cache-control 1 hour TTL) and staled cache (1 year). This ensures all the requests get served with cache/staled content while fetching for a new copy in the backend. I also have CloudFront in front of LiteSpeed servers. I want to set the response cache-control to no-cache when staled content is served so CloudFront can get a copy of the staled content and serving it without caching. This ensures the second request to the same URL is coming back to the litespeed server to get the freshed content. Is there anyway to detect if the response is a staled copy and set/change the response header conditionally?
 
#2
You seem to have a few fundamental misunderstandings. `Cache-Control` is intended for the browser cache to handle static assets (CSS, JS, images, etc.); the main document must never be cached there. Caching dynamic assets in the browser is arguably the biggest mistake you could possibly make! Ideally, you should set the `Cache-Control` TTL to one year, or 31,536,000 seconds.

Using both LSCache and a CDN cache for the main document at the same time is the next biggest mistake you could make. One cache plus another cache does not equal two caches! Therefore, use CloudFront only for static assets, never for dynamic ones.

cdn_2.png

Is there anyway to detect if the response is a staled copy and set/change the response header conditionally?
NO!
 
Top