Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Opensolr Search 4.5.0 Minor update available for module opensolr_search (4.5.0). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Override Cache Control Headers

135 sites Security covered Drupal 8–11
View on drupal.org

This module allows you to customize the Cache-Control HTTP header for individual pages. You can set specific caching rules for each page, including temporary overrides that revert after a set time. This helps in optimizing performance and controlling how your site's content is cached by various intermediaries.

Overview

The Override Cache Control Headers module lets you override the Cache-Control HTTP header on a per-page basis. This is useful for bypassing reverse proxy caches or customizing cache behavior for individual pages.

Key Features

- Flexible Cache Control: Override headers for multiple pages for precise caching control.
- Optimized Performance: Tailor cache settings per page to improve site performance.
- Scheduled Header Overrides: Temporarily override HTTP headers for a set duration (e.g., set `Cache-Control: public, no-cache` for 60 minutes, then revert).
- Easy Configuration: Configure via a simple Drupal admin interface and via Drush.

Installation

  1. Download and install the module using Composer.
  2. Enable the module from the Extend page (`/admin/modules`) or via Drush.

Configuration

  1. Navigate to the module's configuration page at /admin/config/develop/override-cache-control-headers.
  2. Enter the URL and the desired `Cache-Control` headers in the provided textarea. Use the `|` symbol to separate the URL from the headers
    • Example: /sitemap.xml|must-revalidate, no-cache, private
    • One entry per line.
  3. The module also provides option to override the cache control headers for the specific time period which configured under Please enter the URL, headers and expiry time in minutes separated by `|`
    • Example: /sitemap.xml|must-revalidate, no-cache, private|10
    • The last parameter specifies the duration, in minutes, for which the custom headers will be applied to the specified URL. Once the form is saved, the module overrides the cache control headers for that URL. After the configured time period expires, the original headers are automatically restored.
    • One entry per line.
  4. The cache control override is also set using the drush command as like below
    drush occh:set-temp-headers "/sitemap.xml|must-revalidate, no-cache, private|10"

Possible Cache-Control Headers

public: Indicates that the response may be cached by any cache.
private: Indicates that the response is intended for a single user and must not be stored by shared caches.
no-cache: Forces caches to submit the request to the origin server for validation before releasing a cached copy.
no-store: The cache should not store anything about the client request or server response.
max-age=: Specifies the maximum amount of time a resource is considered fresh.
s-maxage=: Overrides max-age or the Expires header, but only for shared caches (e.g., proxies).
must-revalidate: Indicates that once a resource becomes stale, caches must not use the response without successfully validating it with the origin server.
proxy-revalidate: Similar to must-revalidate, but only for shared caches (e.g., proxies).
immutable: Indicates that the response body will not change over time.
stale-while-revalidate=: Allows a cache to serve a stale response while it revalidates it in the background.
stale-if-error=: Allows a cache to serve a stale response if the origin server returns an error.

Example Configuration

  • /sitemap.xml|must-revalidate, no-cache, private
  • /contact|no-store
  • /blog|public, max-age=3600
  • /news|must-revalidate, no-cache, private|10

Permissions

The module provides the following permission:

Administer override cache control headers: Allows users to configure the Cache-Control headers for specific URLs.

Usage

After configuring the URLs and headers, the module will automatically apply the specified Cache-Control headers to the matching URLs. The module listens to the `kernel.response` event and modifies the response headers based on the configuration.

Technical Details

  • Configuration form: OverrideCacheControlHeadersSettingsForm
  • Event subscriber: OverrideCacheControlHeaders (listens to kernel.response)
  • Configuration stored in: override_cache_control_headers.settings.yml
  • Drush command: OverrideCacheControlHeadersDrushCommands
  • Provides a hook for custom actions when headers are set (e.g., clearing Varnish/Cloudflare cache):
          /**
            * Hook to allow actions after headers are set.
            *
            * @param array $url
            *   Array of affected URLs.
          */
          function hook_override_cache_control_headers(array $url) {
          }
        

Testing

To run unit tests:

phpunit --group override_cache_control_headers

  • tests/src/Unit/OverrideCacheControlHeadersTest.php
  • tests/src/Unit/UtilityTest.php

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
10
Tracked since
Mar 2025
Latest release
4 weeks ago
Releases (12 mo)
4 ▼ from 6
Maintenance
Active

Release Timeline

Releases

Version Type Core Release date
1.0.5 Stable 8–11 Aug 4, 2026
1.0.4 Stable 8–11 Aug 3, 2026
1.0.3 Stable 8–11 Nov 26, 2025
1.0.2 Stable 8–11 Nov 21, 2025
1.0.1 Stable 8–11 Jul 16, 2025
1.0.0 Stable 8–11 Jul 15, 2025
1.0.0-beta1 Pre-release 8–11 Jun 3, 2025
1.0.0-alpha2 Pre-release Mar 25, 2025
1.x-dev Dev Mar 25, 2025
1.0.0-alpha1 Pre-release 8–11 Mar 25, 2025