Hi Community,
Is there an option to purge the CDN cache for a particular website when multiple websites are installed on a single AEM as a Cloud Service environment? I understand that this might be achievable by adding a surrogate key to all pages within one website, but I’m wondering if there is a simpler or more straightforward way to accomplish this, as it seems to be a very basic requirement. Any insights or recommendations would be greatly appreciated!
Regards,
Rustam
Views
Replies
Total Likes
Based on Adobe's official documentation, using surrogate keys is the most straightforward and recommended method for purging CDN cache for a specific website in a multi-site AEM as a Cloud Service environment. Unfortunately, there is no simpler built-in option that automatically segments cache by website without configuration.
AEMasCS provides three purge variations:
Single URL purge - Purges one resource at a time
Surrogate key purge - Purges multiple resources grouped by key(s) (recommended for your use case)
Full purge - Purges all cached resources (use with caution)
There is no native "site-based" filtering in the CDN purge API. The CDN cache doesn't automatically know which pages belong to which website in your multi-site setup. Surrogate keys exist specifically to solve this problem by allowing you to tag and group related content for selective purging.
You can add the Surrogate-Key header using Apache mod_headers in your Dispatcher configuration. This is typically the simplest approach:
# In your vhost file or dispatcher configuration
<LocationMatch "^/content/site1/.*\.html$">
Header set Surrogate-Key "site1 html-content"
</LocationMatch>
<LocationMatch "^/content/site2/.*\.html$">
Header set Surrogate-Key "site2"
</LocationMatch>If you need more dynamic control, you can add the Surrogate-Key header programmatically using a Sling Filter:
@component(service = Filter.class)
@ServletFilter(scope = SlingServletFilterScope.REQUEST)
public class SurrogateKeyFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;
String path = slingRequest.getResource().getPath();
if (path.startsWith("/content/site1/")) {
slingResponse.setHeader("Surrogate-Key", "site1");
} else if (path.startsWith("/content/site2/")) {
slingResponse.setHeader("Surrogate-Key", "site2");
}
chain.doFilter(request, response);
}
}Before using the Purge API, you need to Configure Purge API Token in your AEM project's cdn.yaml file and Deploy the configuration via Cloud Manager Config Pipeline (of course you've to store the purge key as a Cloud Manager secret-type environment variable). More info here.
Btw, ensure the dispatcher cache is also invalidated before CDN purge, as the CDN will fetch from Dispatcher when cache expires
Hi @giuseppebaglio ,
Thank you for your very detailed response. I appreciate your insights and wanted to mention that I am aware of the need to clear the dispatcher cache as well. Given that we have a dedicated vhost file for each website, we will likely set the surrogate key header directly at the dispatcher tier.
Additionally, I created an Adobe support ticket regarding this query. Adobe suggested using the X-Forwarded-Host header as mentioned in the Interaction with Custom CDN ([Purging the CDN cache | Adobe Experience Manager]), but unfortunately, this approach did not work for us, and I am skeptical that it will work in this scenario. However, since we can send PURGE requests directly to the hostname (e.g., PURGE https://site1.example.org), the CDN is fully aware of the hostname, and I do not see any technical obstacle that would prevent the CDN from purging everything under a particular domain name.
If no one in this forum provides a working solution, or if Adobe confirms that the surrogate key is the only viable method, I will mark your answer as correct.
Thank you very much once again for your help,
Rustam
Views
Replies
Total Likes
The X-Forwarded-Host header tells Adobe CDN which domain variant to purge. This is critical because Adobe CDN can cache the same path differently for different domains (different cache keys). Besides the purge only affects the exact /resource-path specified in the URL for that specific domain -- so it cannot be used for your use case.
Views
Replies
Total Likes
Hi @user62746 ,
In AEM as a Cloud Service, you can’t purge CDN cache for just one site directly cache invalidation happens at the environment level.
To target a specific website, the recommended approach is to:
Use surrogate keys (tags) on pages and assets of that site.
Then trigger cache invalidation using those keys via the AEM CDN API or Dispatcher Flush agent.
There is no simpler built-in “per-site” purge; surrogate keys are the official and safest method.
Views
Replies
Total Likes
Hello @user62746 ,
There is no safer or simpler alternative than implementing Surrogate-Key headers to enable per-website cache purging when running multiple sites on a single AEMaaCS environment.
Path and domain purges have risks; Surrogate-Key is robust, flexible, and recommended by both Adobe and CDN providers.
Views
Replies
Total Likes
Views
Likes
Replies