Cache overview

更新时间:
复制 MD 格式

When you use CDN to accelerate static resources, CDN caches the resources on the nearest POP. When you access a resource, you can retrieve it directly from the POP, which reduces latency and improves access efficiency. If the requested content does not exist on the POP or has expired, CDN requests the latest data from the origin server.

Cache-related features

Use the following features to control the caching behavior for your accelerated domain names.

Feature

Description

Configure TTL for cache rules

By configuring cache expiration rules, you can precisely control the cache duration for resources on CDN points of presence (POPs) to balance content freshness, access performance, and origin-fetch costs. This document explains how cache rules work, how to configure and validate them, and provides troubleshooting guidance and best practices.

Configure TTL for status codes

When a CDN or POP fetches a resource, the origin server returns a status code. You can configure a TTL for these status codes in Alibaba Cloud CDN or . When a client requests the same resource again, the POP can directly respond with the cached status code without an origin fetch. This reduces the load on your origin server. When the TTL for the status code expires, the next request triggers an .

Configure TTL for status codes (Honor Origin)

This feature lets you set the time-to-live (TTL) for static resources on points of presence (POPs) based on the status codes that your origin returns.

Modify outgoing response headers

Outgoing response headers are HTTP response components containing parameters that control client caching behavior. By modifying these headers, CDN includes your configured headers in responses to requests for your accelerated domain name. This allows you to implement features such as cross-origin resource sharing (CORS).

Configure custom error pages

After you create a custom error page, when the requested content does not exist or an error occurs, the point of presence (POP) returns the custom error page instead of the default error page. A custom error page improves user experience and allows users to view more user-friendly error prompts.

Rewrite access URLs

If the resource path on the origin server changes, the corresponding resource path on a POP also changes. If a client requests the original URL, the POP can rewrite the request URL and redirect it to the new path. This process reduces origin-pull requests and improves client performance.

Configure a custom cache key

You can consolidate requests that access the same file into a single cache key. This prevents different requests from being cached as different files and reduces origin fetches.

By configuring a custom cache key, you can define rules to generate a cache key based on different parts of an HTTP request, such as the URI, request parameters, HTTP request headers, or custom variables. This improves the cache hit ratio, reduces origin fetches, and decreases response time and bandwidth consumption.

Configure a shared cache

Cache sharing allows multiple accelerated domain names under the same Alibaba Cloud account to share cached resources on CDN points of presence (POPs). When multiple domain names serve many common assets, such as images, CSS, and JavaScript files, configuring cache sharing prevents duplicate origin fetches. This improves the cache hit ratio and reduces origin traffic.

Configure cross-origin resource sharing (CORS)

When a browser requests a resource from a different origin, it checks whether the server allows the cross-origin request. Alibaba Cloud CDN handles this by comparing the Origin header in each request against the Access-Control-Allow-Origin value you configure on the CDN node, and returning the header only when there is a match. This lets you control cross-origin access at the CDN layer without relying solely on your origin server.

FAQ