Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions modules/next/src/Plugin/Next/Revalidator/CacheTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Symfony\Component\HttpFoundation\Response;

/**
* Provides a revalidator for revalidating Next Site references by cache tags.
* Cache tag based on-demand revalidation plugin.
*
* @Revalidator(
* id = "cache_tag",
Expand Down Expand Up @@ -56,29 +56,20 @@ public function revalidate(EntityActionEvent $event): bool {
return FALSE;
}

$tags = $entity->getCacheTags() ?? [];
if ($entity->getEntityTypeId() == 'menu_link_content') {
$tags[] = $entity->getEntityTypeId() . ':' . $entity->getMenuName();
}
else {
$tags[] = $entity->getEntityTypeId() . '_list';
$tags[] = $entity->getEntityTypeId() . '_list:' . $entity->bundle();
}
$cache_tags = implode(',', $entity->getCacheTags());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minnur I think the entity list tags we still have to add manually, at least in my test for nodes for example $entity->getCacheTags only gave node:8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about this, but apparently if we do this:

$entity->getEntityType()->getListCacheTags();

We should get the correct list tag. The one with the bundle at the end we still need to create manually.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find! I added that to the plugin. See db2690b
I noticed $entity->getEntityType()->getListCacheTags(); does not have entity_type_list:bundle. So I looked at \Drupal\Entity\EntityBase class and found a method getListCacheTagsToInvalidate() that adds that to the invalidation list and implemented the same logic in the plugin.


/** @var \Drupal\next\Entity\NextSite $site */
foreach ($sites as $site) {
try {
$tags_string = implode(',', $tags);
$revalidate_url = $site->buildRevalidateUrl(['tags' => $tags_string]);

$revalidate_url = $site->buildRevalidateUrl(['tags' => $cache_tags]);
if (!$revalidate_url) {
throw new \Exception('No revalidate url set.');
}

if ($this->nextSettingsManager->isDebug()) {
$this->logger->notice('(@action): Revalidating tags %tags for the site %site. URL: %url', [
$this->logger->notice('(@action): Revalidating tags %list for the site %site. URL: %url', [
'@action' => $event->getAction(),
'%tags' => $tags_string,
'%list' => $cache_tags,
'%site' => $site->label(),
'%url' => $revalidate_url->toString(),
]);
Expand All @@ -87,9 +78,9 @@ public function revalidate(EntityActionEvent $event): bool {
$response = $this->httpClient->request('GET', $revalidate_url->toString());
if ($response && $response->getStatusCode() === Response::HTTP_OK) {
if ($this->nextSettingsManager->isDebug()) {
$this->logger->notice('(@action): Successfully revalidated tags %path for the site %site. URL: %url', [
$this->logger->notice('(@action): Successfully revalidated tags %list for the site %site. URL: %url', [
'@action' => $event->getAction(),
'%tags' => $tags_string,
'%list' => $cache_tags,
'%site' => $site->label(),
'%url' => $revalidate_url->toString(),
]);
Expand Down
Loading