Skip to main content

Drupal Cache max-age | Cache API

Drupal 10, 9 cache max-age is when a particular resource, such as a page, block, or view, should be considered fresh and valid. This value is set in the HTTP headers of the response that Drupal sends to the client's browser, and it tells the browser how long it should cache the resource before requesting it again from the server.

In Drupal 10, most resources' default cache max-age value is set to 1 hour (3600 seconds). However, this value can be overridden in various ways, depending on the specific caching mechanism.

For example, the Drupal 10-page cache can be configured to use different cache max-age values based on the user's role or permissions, the URL path, or other factors. Similarly, the Drupal 10 block cache and view cache can be configured to use different cache max-age values based on the cached block or view.

To configure the cache max-age for a particular resource in Drupal 10, you can use various caching-related functions and hooks provided by the Drupal API, such as the CacheableResponseInterface::setMaxAge() method for HTTP responses, or the hook_cache_max_age_alter() hook for altering the cache max-age value for specific resources.