Loading...


Related Products


Date Published: June 30, 2022

Configuring Platform CDN with Drupal 7 and Cache Control Headers

Better control over cached objects in Drupal 7 can be achieved by installing the following modules:

The Acquia Purge and Cache Expiration modules combine to create a cache invalidation approach for objects cached in Acquia Varnish. 

Note: Static assets such as CSS fonts, images and Javascript files are given Cache-Control headers by the Apache web server, and are cached for 2 weeks by default.

If you are a Platform CDN user, you may want broader control over objects cached in the CDN. Install the Chaos Tools Suite and HTTP Response Headers modules.

If you are manually installing these modules copy them into the contrib folder like so:

~/dev/d7cdnsandbox/docroot/sites/all/modules/contrib>tree -d -L 1
                  .
                  ├── acquia_purge
                  ├── ctools
                  ├── expire
                  └── http_response_headers

Once you have installed the modules, open your site and visit admin/modules. Complete the installation and configuration of the Acquia Purge and Cache Expiration modules by following these instructions: Installing Acquia Purge and Expires modules on D7, Configuring Acquia Purge on D7, and the corresponding FAQ Page.

To configure HTTP Response Headers, visit the Chaos Tools Suite section, and enable 'Chaos Tools'.  In the Other section, enable 'HTTP Response Headers' and 'HTTP Response Headers UI'.

Next, navigate to admin/config/system/http-response-headers:

  • Click on the Settings tab. 
  • Select 'Cache-Control' as an allowed header.  Save configuration.
  • In the 'List' tab, click 'add' and set:
    • Description: Cache-Control
    • HTTP Header: Cache-Control (this is the header that you *allowed* in the previous step)
    • HTTP Header Value: 
    • max-age=60, s-maxage=1209600 
    • Visibility settings: (leave default)

The Cache-Control header sets the following directives in Acquia Varnish:

  • s-maxage=1209600: Cache objects in Varnish for two weeks (1209600 seconds)
  • max-age=60: Cache objects in the browser for 60 seconds. 

The long Time-To-Live (TTL) at Acquia Varnish (1209600 seconds) is desirable because most cached paths at Acquia Varnish are expired by the Acquia Purge and Cache Expiration modules whenever content changes. The shorter TTL at the browser (60) is desirable because your application has no way to purge the browser cache.

Now repeat the steps above to set the Surrogate Control header:

  • Click on the Settings tab. 
  • Select 'Surrogate-Control' as an allowed header.  Save configuration.
  • In the 'List' tab, click 'add' and set:
    • Description: Surrogate-Control
    • HTTP Header: Surrogate-Control (this is the header that you *allowed* in the previous step)
    • HTTP Header Value: 
    • max-age=180
    • Visibility settings: (leave default)

This will set the Surrogate-Control header for dynamic content to: `Surrogate-Control: max-age=180`.  This header instructs Platform CDN to cache objects for three minutes (180 seconds). This short cache lifetime is desirable because D7 has no way to purge individual paths from Platform CDN, so setting a low TTL at the edge ensures that the oldest age of any cached object will be, at most, three minutes.

Note: When testing, you may want to set the Surrogate-Control header to a very low value (1-5 seconds). The CDN strips the Surrogate-Control header on arrival, so you will never see the header in a curl response. Instead, set a low TTL, then test by changing content on a page, clearing your browser cache and visiting the page in an anonymous seion (i.e., a Chrome incognito browser session). After your tests are complete, change the Surrogate-Control: max-age directive to as high a TTL as tolerable.

You may need to purge all caches if you want these changes to take effect immediately rather than waiting for the current cached pages to expire.

For information about how the Drupal application sets cache headers see these articles:

https://www.drupal.org/docs/8/api/responses/cacheableresponseinterface#debugging

https://www.drupal.org/project/renderviz

Did not find what you were looking for?

If this content did not answer your questions, try searching or contacting our support team for further assistance.

Back to Section navigation