Skip to content

Instantly share code, notes, and snippets.

@Greg-Boggs
Last active July 24, 2019 22:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Greg-Boggs/ad236176d8506e6aaa1b8f80aa4cdac5 to your computer and use it in GitHub Desktop.
Save Greg-Boggs/ad236176d8506e6aaa1b8f80aa4cdac5 to your computer and use it in GitHub Desktop.
Expire the cache for Breadcrumbs when the page changes in Drupal 8
<?php
// Expire the cache per url.
$breadcrumb->addCacheContexts(['url.path']);
// Expire cache context for config changes.
$breadcrumb->addCacheableDependency($this->config);
// Handle views path expiration cache expiration.
$parameters = $route_match->getParameters();
foreach ($parameters as $key => $parameter) {
if ($key === 'view_id') {
$breadcrumb->addCacheTags(['config:views.view.' . $parameter]);
}
if ($parameter instanceof CacheableDependencyInterface) {
$breadcrumb->addCacheableDependency($parameter);
}
}
// Expire cache by languages and config changes.
$breadcrumb->addCacheContexts(['url.path', 'languages']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment