Sub topic 12
Making sure caches and CDNs serve the new facts
Assume you know basic HTML, how a web page is served, and what a crawler does. You should also understand JSON and have some experience maintaining a content or e-commerce site.
A cache stores a copy of a response so it can be served faster. A content delivery network (CDN) stores copies at locations near visitors. Caches improve speed, but they can keep showing an old price, stock status, or date after the origin site has changed.
What happens when a fact changes
Suppose a product price changes from €89 to €79.
- The product record changes at the origin.
- The origin renders the new visible price and structured data.
- The CDN may still have the old HTML.
- A visitor may receive the old HTML until its time to live (TTL) expires.
- Search crawlers and product platforms may also receive the old response.
A TTL is the length of time that a cache may use a stored response without checking the origin. A long TTL reduces origin traffic but increases the time that stale facts can remain visible.
| Fact | Reasonable caching approach | Extra action after a change |
|---|---|---|
| Product price or stock | Short TTL, such as 5 minutes | Purge the product URL |
| Article text | Longer TTL, such as 1 hour | Purge after a meaningful edit |
| Versioned CSS or JavaScript | Long TTL | Publish a new filename |
| Personalized account page | Do not share publicly | No public CDN caching |
Choose headers that match the fact
For frequently changing pages, use a short public cache period and allow revalidation:
curl -sS -D - -o /dev/null https://example.com/p/trail-runner-2Inspect the response for headers similar to these:
Cache-Control: public, max-age=300, stale-while-revalidate=60
ETag: "product-tr2-v42"
Last-Modified: Fri, 20 Nov 2026 08:00:00 GMTmax-age=300 allows five minutes of reuse. stale-while-revalidate=60 allows a cache to serve an older response briefly while it asks the origin for a newer one. Use this option only when a short period of stale data is acceptable.
An ETag is a version identifier for the response. A browser or CDN can send it back in an If-None-Match request. If the content has not changed, the origin returns 304 Not Modified instead of sending the full page.
Last-Modified supports the same pattern using a timestamp. Set it to the time of the last meaningful content change, not the time a request happened.
Purge caches in the correct order
A purge removes cached copies before their TTL expires. The safe sequence is:
- Commit the new product or article data.
- Deploy the renderer or page.
- Confirm the origin returns the new facts.
- Purge the affected URL or cache key.
- Request the URL through the CDN.
- Check the visible text, JSON-LD, and response headers.
Purging before the origin is ready can refill the CDN with the old response. Purge only the affected URLs when possible. A full-site purge increases origin load and can slow every visitor.
Track cache layers
A page can pass through a browser cache, a CDN, a reverse proxy, and an application cache. Inspect headers such as Age, ETag, and a provider-specific cache status header. Test from more than one location when a price or availability change is urgent.
Verify the whole delivery path
Automated checks should compare the product record with the origin HTML, JSON-LD, sitemap, and product feed. A deployment check should fail if the origin has the new price but a public request still returns the old one after the purge window.
Exercise
A product price changed, but visitors still see the old price. What should you check first?
Show answer
Check the origin response first. If it is current, inspect cache headers and purge the affected CDN URL. If the origin is stale, fix the source or renderer before purging again.