CDN (Content Delivery Network) handles origin server resource updates through a combination of caching mechanisms and refresh strategies to ensure users receive the latest content while maintaining performance. Here's how it works:
Cache Expiration (TTL-based Refresh):
CDN nodes cache content based on a predefined Time-To-Live (TTL) value set by the origin server or CDN configuration. When the TTL expires, the CDN fetches the updated content from the origin server. For example, if an image is cached for 1 hour, the CDN will serve the cached version for that period and then refresh it from the origin after expiration.
Manual Cache Purge:
When immediate updates are needed (e.g., fixing a website error or updating critical files), the CDN allows manual purging of specific files or directories. This forces the CDN to fetch fresh content from the origin on the next request. For instance, if a company updates its homepage HTML, it can purge the cached version to ensure users see the latest page immediately.
Versioning or File Name Changes:
A common practice is to use versioned file names (e.g., style-v2.css instead of style.css) or query strings (e.g., script.js?v=2). This ensures the CDN treats the updated file as a new resource, bypassing the old cached version entirely.
Origin Shield and Smart Refresh:
Some CDNs use an origin shield (a centralized caching layer) to reduce origin load. When updates are detected, the shield coordinates with the origin to refresh content efficiently. Additionally, smart refresh mechanisms can detect changes on the origin and proactively update the CDN cache without manual intervention.
Example:
A media company uploads a new video to its origin server. The CDN initially serves the old video from cache due to a 24-hour TTL. To ensure viewers access the latest video, the company manually purges the video URL from the CDN, triggering an immediate fetch from the origin.
For such scenarios, Tencent Cloud CDN provides features like URL purge, cache refresh, and versioned file delivery to streamline origin updates and ensure fast content delivery.