Browse Source

Make use of audit cache tag more explict to the entity.

pull/2/head
Nigel Banks 3 years ago
parent
commit
367e949f30
  1. 10
      dgi_fixity.module
  2. 5
      src/Controller/FixityCheckController.php
  3. 9
      src/Entity/FixityCheck.php
  4. 8
      src/FixityCheckInterface.php

10
dgi_fixity.module

@ -202,18 +202,16 @@ function dgi_fixity_file_delete(EntityInterface $entity) {
* Implements hook_ENTITY_TYPE_revision_create(). * Implements hook_ENTITY_TYPE_revision_create().
*/ */
function dgi_fixity_fixity_check_revision_create(EntityInterface $entity) { function dgi_fixity_fixity_check_revision_create(EntityInterface $entity) {
Cache::invalidateTags([ /** @var \Drupal\dgi_fixity\FixityCheckInterface $entity*/
'fixity_check:' . $entity->id() . ':revisions_list', Cache::invalidateTags($entity->getAuditCacheTags());
]);
} }
/** /**
* Implements hook_ENTITY_TYPE_revision_delete(). * Implements hook_ENTITY_TYPE_revision_delete().
*/ */
function dgi_fixity_fixity_check_revision_delete(EntityInterface $entity) { function dgi_fixity_fixity_check_revision_delete(EntityInterface $entity) {
Cache::invalidateTags([ /** @var \Drupal\dgi_fixity\FixityCheckInterface $entity*/
'fixity_check:' . $entity->id() . ':revisions_list', Cache::invalidateTags($entity->getAuditCacheTags());
]);
} }
/** /**

5
src/Controller/FixityCheckController.php

@ -211,10 +211,7 @@ class FixityCheckController extends ControllerBase {
// Date displayed varies by timezone. // Date displayed varies by timezone.
'timezone', 'timezone',
], ],
'tags' => [ 'tags' => $fixity_check->getAuditCacheTags(),
// Invalidated by revision create/delete hooks.
'fixity_check:' . $fixity_check->id() . ':revisions_list',
],
'bin' => 'render', 'bin' => 'render',
]; ];
$this->renderer->addCacheableDependency($build, $fixity_check); $this->renderer->addCacheableDependency($build, $fixity_check);

9
src/Entity/FixityCheck.php

@ -321,6 +321,15 @@ class FixityCheck extends ContentEntityBase implements FixityCheckInterface {
$file->label(); $file->label();
} }
/**
* {@inheritdoc}
*/
public function getAuditCacheTags() {
return [
'fixity_check:' . $this->id() . ':revisions_list',
];
}
/** /**
* Defines allowed states for AllowedValues constraints. * Defines allowed states for AllowedValues constraints.
* *

8
src/FixityCheckInterface.php

@ -226,4 +226,12 @@ interface FixityCheckInterface extends ContentEntityInterface, RevisionableInter
*/ */
public function setQueued(int $queued): FixityCheckInterface; 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();
} }

Loading…
Cancel
Save