Friday, 7 November 2025

How to Enable or Disable Caching in AEM as a Cloud Service

Adobe Experience Manager (AEM) as a Cloud Service uses caching to speed up content delivery and reduce load on the publish servers. Caching works across multiple layers- the CDN, Dispatcher, and browser - to store and serve content quickly. However, you may need to enable or disable caching depending on your project requirements.

Understanding Caching

Caching stores copies of responses so users can access content faster. When caching is enabled, repeated requests are served directly from the cache instead of the AEM origin. Disabling caching ensures fresh content is always fetched directly from AEM.

How to Enable Caching

To enable caching, you can configure HTTP response headers that tell the CDN and browser how long to keep content in cache. You can apply this through the dispatcher configuration or programmatically in your code.

Dispatcher Configuration Example:


Header unset Cache-Control Header unset Surrogate-Control Header unset Expires Header set Cache-Control "max-age=600, stale-while-revalidate=600, stale-if-error=600" Header set Surrogate-Control "max-age=600, stale-while-revalidate=600, stale-if-error=600"

In this setup, the content remains fresh for 10 minutes (max-age=600) and continues to serve cached data briefly during revalidation or errors for improved performance.

Programmatic Approach: You can also set the same headers from a Sling Servlet or Filter to apply caching rules to specific responses.

How to Disable Caching

In some cases, such as dynamic, personalized, or secure content, you may not want caching. To disable caching, adjust your response headers to mark the response as private or non-cacheable.

Dispatcher Configuration Example:


Header unset Cache-Control Header unset Surrogate-Control Header unset Expires Header always set Cache-Control "private" Header always set Surrogate-Control "private"

This configuration ensures that content is not stored in the CDN or shared caches. You can also apply the same logic in a custom servlet or filter by adding the header Cache-Control: private.

When to Enable or Disable Caching

Scenario Recommended Action
Public or static content (images, HTML pages) Enable caching with a defined time-to-live (TTL) for better performance.
Personalized or dynamic data Disable caching or set responses to private to prevent serving outdated or user-specific data.
Development or testing environments Disable caching to see real-time changes immediately.
Mixed content types Use selective caching rules in dispatcher or via code to manage caching per path or content type.

Best Practices

  • Always set explicit caching headers to avoid default or unintended behavior.
  • Test your caching configuration in staging before applying to production.
  • Use stale-while-revalidate and stale-if-error for better user experience under load.
  • Regularly review which pages should bypass caching (e.g., forms, user dashboards).

By managing caching properly, AEM as a Cloud Service can balance high performance with real-time content accuracy — ensuring users always get the right experience.


No comments:

Post a Comment