The Stack Overflow podcast is back! Listen to an interview with our new CEO.
2 Fix preprocess function name
source | link

There are three layers where rendered content can be cached:

  • The Page Cache, which stores complete pages based on the URL for anonymous users.
  • The Dynamic Page Cache, which stores pages with placeholders for dynamic content that is rendered on each request.
  • The Render Cache, which stores individual rendered elements.

Each has a corresponding cache bin that can be disabled during development in settings.php


To set an additional cache context in hook_preprocess, so that the Dynamic Page cache knows to re-render that fragment and the render cache stores variants as needed, update the #cache variable:

function MY_MODULE_hook_preprocess_pagehook_preprocess_HOOK(&$variables) {
  $variables['#cache']['contexts'][] = 'url.query_args:exclude_urls';
}

There are three layers where rendered content can be cached:

  • The Page Cache, which stores complete pages based on the URL for anonymous users.
  • The Dynamic Page Cache, which stores pages with placeholders for dynamic content that is rendered on each request.
  • The Render Cache, which stores individual rendered elements.

Each has a corresponding cache bin that can be disabled during development in settings.php


To set an additional cache context in hook_preprocess, so that the Dynamic Page cache knows to re-render that fragment and the render cache stores variants as needed, update the #cache variable:

function MY_MODULE_hook_preprocess_page(&$variables) {
  $variables['#cache']['contexts'][] = 'url.query_args:exclude_urls';
}

There are three layers where rendered content can be cached:

  • The Page Cache, which stores complete pages based on the URL for anonymous users.
  • The Dynamic Page Cache, which stores pages with placeholders for dynamic content that is rendered on each request.
  • The Render Cache, which stores individual rendered elements.

Each has a corresponding cache bin that can be disabled during development in settings.php


To set an additional cache context in hook_preprocess, so that the Dynamic Page cache knows to re-render that fragment and the render cache stores variants as needed, update the #cache variable:

function hook_preprocess_HOOK(&$variables) {
  $variables['#cache']['contexts'][] = 'url.query_args:exclude_urls';
}
1
source | link

There are three layers where rendered content can be cached:

  • The Page Cache, which stores complete pages based on the URL for anonymous users.
  • The Dynamic Page Cache, which stores pages with placeholders for dynamic content that is rendered on each request.
  • The Render Cache, which stores individual rendered elements.

Each has a corresponding cache bin that can be disabled during development in settings.php


To set an additional cache context in hook_preprocess, so that the Dynamic Page cache knows to re-render that fragment and the render cache stores variants as needed, update the #cache variable:

function MY_MODULE_hook_preprocess_page(&$variables) {
  $variables['#cache']['contexts'][] = 'url.query_args:exclude_urls';
}