From 367e949f3064dbe99b8fcc05eac93c7152259a19 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Tue, 19 Apr 2022 13:57:54 +0100 Subject: [PATCH] Make use of audit cache tag more explict to the entity. --- dgi_fixity.module | 10 ++++------ src/Controller/FixityCheckController.php | 5 +---- src/Entity/FixityCheck.php | 9 +++++++++ src/FixityCheckInterface.php | 8 ++++++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/dgi_fixity.module b/dgi_fixity.module index a974756..8d5b84e 100644 --- a/dgi_fixity.module +++ b/dgi_fixity.module @@ -202,18 +202,16 @@ function dgi_fixity_file_delete(EntityInterface $entity) { * Implements hook_ENTITY_TYPE_revision_create(). */ function dgi_fixity_fixity_check_revision_create(EntityInterface $entity) { - Cache::invalidateTags([ - 'fixity_check:' . $entity->id() . ':revisions_list', - ]); + /** @var \Drupal\dgi_fixity\FixityCheckInterface $entity*/ + Cache::invalidateTags($entity->getAuditCacheTags()); } /** * Implements hook_ENTITY_TYPE_revision_delete(). */ function dgi_fixity_fixity_check_revision_delete(EntityInterface $entity) { - Cache::invalidateTags([ - 'fixity_check:' . $entity->id() . ':revisions_list', - ]); + /** @var \Drupal\dgi_fixity\FixityCheckInterface $entity*/ + Cache::invalidateTags($entity->getAuditCacheTags()); } /** diff --git a/src/Controller/FixityCheckController.php b/src/Controller/FixityCheckController.php index 1c3ec5c..768d753 100644 --- a/src/Controller/FixityCheckController.php +++ b/src/Controller/FixityCheckController.php @@ -211,10 +211,7 @@ class FixityCheckController extends ControllerBase { // Date displayed varies by timezone. 'timezone', ], - 'tags' => [ - // Invalidated by revision create/delete hooks. - 'fixity_check:' . $fixity_check->id() . ':revisions_list', - ], + 'tags' => $fixity_check->getAuditCacheTags(), 'bin' => 'render', ]; $this->renderer->addCacheableDependency($build, $fixity_check); diff --git a/src/Entity/FixityCheck.php b/src/Entity/FixityCheck.php index db521da..1c95791 100644 --- a/src/Entity/FixityCheck.php +++ b/src/Entity/FixityCheck.php @@ -321,6 +321,15 @@ class FixityCheck extends ContentEntityBase implements FixityCheckInterface { $file->label(); } + /** + * {@inheritdoc} + */ + public function getAuditCacheTags() { + return [ + 'fixity_check:' . $this->id() . ':revisions_list', + ]; + } + /** * Defines allowed states for AllowedValues constraints. * diff --git a/src/FixityCheckInterface.php b/src/FixityCheckInterface.php index b1c7f2d..aedd833 100644 --- a/src/FixityCheckInterface.php +++ b/src/FixityCheckInterface.php @@ -226,4 +226,12 @@ interface FixityCheckInterface extends ContentEntityInterface, RevisionableInter */ public function setQueued(int $queued): FixityCheckInterface; + /** + * The cache tags associated with the audit display of this entity. + * + * @return string[] + * The cache tags. + */ + public function getAuditCacheTags(); + }