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.
How cache sharing works
After you configure cache sharing, CDN rewrites the Host header using the rewrite_host function. The origin fetch request's Host is replaced with the target domain name's Host (the share_host parameter). This makes requests from different domain names appear as the same resource at the CDN POP level. After you configure cache sharing for an accelerated domain name, the shared domain name replaces the accelerated domain name only during cache key lookup and generation. This does not affect the origin URL or origin host of the accelerated domain name.
Assume two domain names, a.example.com and b.example.com, both use the same Bootstrap framework and reference identical image, CSS, and JS files. The CDN behaves differently depending on whether cache sharing is configured.
Without cache sharing
Each domain name maintains an independent cache space by default. Even if two domain names point to the same origin server, CDN POPs treat them as different resources because the domain name is part of the cache key.
User 1 accesses
a.example.com/image.png. The image is cached ina.example.com's cache space.User 2 accesses
b.example.com/image.png. Even though the image already exists ina.example.com's cache, CDN fetches it again from the origin server and caches it separately inb.example.com's cache space.
This results in duplicate caching and redundant origin fetches for identical resources.
With cache sharing
User 1 accesses
a.example.com/image.png. The image is cached in the shared cache space.User 2 accesses
b.example.com/image.png. CDN identifies the resource as identical and serves it directly from the shared cache without an origin fetch.
Resources are fetched from the origin server once. Subsequent requests, regardless of the domain name, are served directly from the shared cache.
Same origin: shared cache behavior
When two domain names share the same origin URL (for example, both use origin.example.com), they naturally fetch resources from the same origin. With cache sharing configured, requests from both domain names map to the same cache entries, effectively sharing a single cache space.
Different origins: cross-origin cache sharing
When two domain names use different origin URLs, cache sharing still enables cross-origin cache reuse. For example, if origin-a.example.com and origin-b.example.com serve resources at identical URL paths, cache sharing replaces the accelerated domain name with the shared domain name during cache key generation.
When to use cache sharing
Use cache sharing when:
You have two or more accelerated domain names under the same Alibaba Cloud account.
Multiple domain names serve identical or largely overlapping static assets.
You want to reduce redundant origin fetches caused by cache misses across domain names.
Do not use cache sharing when:
You have only one accelerated domain name.
Your domain names serve entirely different content with no shared assets.
Your content is primarily dynamic and not suitable for CDN caching.
Prerequisites
Before you configure cache sharing, make sure that you have:
An Alibaba Cloud account with the CDN service activated
At least two accelerated domain names in the Enabled state under the same account
Resource Access Management (RAM) user permissions for CDN console configuration, if you are using a RAM user
Limits
Maximum candidates — The candidate list displays up to 500 domain names.
Resource group isolation — If the current domain name belongs to a specific resource group, the candidate list is filtered by that resource group.
Single selection — Cache sharing supports only one target domain name. Multiple shared targets cannot be configured simultaneously.
Deletion protection — When domain name A's cache sharing target is set to domain name B, the system prevents deletion of domain name B. You must first delete or modify the cache sharing configuration on domain name A before deleting domain name B.
Usage notes
If you delete a shared accelerated domain name, this decreases the cache hit ratio for other domains that use its cache. Exercise caution when you disable or delete a domain name.
Migrating an accelerated domain name that uses cache sharing to another account preserves the cache sharing configuration on the migrated domain. However, because cache sharing only operates within a single account, you may need to reconfigure the target if it remains in the original account.
Configure cache sharing
Log on to the CDN console.
In the left-side navigation pane, click Domain Names.
On the Domain Names page, find the target domain name.
In the left-side navigation pane of the domain name details page, click Cache.
Click the Cache Sharing tab.
Click Configure.
In the dialog box that appears, select a target accelerated domain name from the drop-down list.
The drop-down list displays only the accelerated domain names in the Enabled state under the current account. You can perform a fuzzy search using the search box. Up to 500 candidate domain names are displayed. The list automatically excludes the domain name you are currently configuring.
Click OK to save the configuration.
After the configuration is complete, the configured shared cache domain name appears on the Cache Sharing tab.
Modify the cache sharing configuration
Navigate to the page for the target domain name.
Click Configure.
In the dialog box that appears, select a new target accelerated domain name and click OK.
After the modification is saved, the new target domain name is displayed on the Cache Sharing tab. Requests from the current domain name will now use the new target domain name's cache space at CDN POPs.
Delete the cache sharing configuration
Navigate to the page for the target domain name.
Click Delete Configuration.
In the confirmation dialog box, click OK.
After the deletion is complete, the page displays Not configured. The domain name resumes using its independent cache space. Previously shared cached content is no longer accessible from this domain name's perspective.
FAQ
Can different domain names share cached content without configuring cache sharing?
No. The CDN cache key includes the domain name, so requests to different domain names are treated as different resources. This applies even when both domains request the same file from the same origin server.
Why didn’t the cache hit rate improve after configuration?
To fix this, you need to check two main things:
Make sure that both domain names are pointing to the exact same resource URLs (file paths). If the paths are different, the system treats them as separate files, and the cache won't work as expected.
Review your cache expiration settings (TTL). Ensure they are set reasonably. If the expiration time is too short, the cache expires before it can be used again, which prevents the hit rate from increasing.