Skip to content

Commit

Permalink
Adjust caching for embargo and related access control.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-vessey committed May 9, 2024
1 parent b54b44a commit 63d0178
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Access/EmbargoAccessCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public function access(EntityInterface $entity, AccountInterface $user) {
)->render()
);
array_map([$state, 'addCacheableDependency'], $embargoes);

$type = $this->entityTypeManager->getDefinition('embargo');
$state->addCacheTags($type->getListCacheTags())
->addCacheContexts($type->getListCacheContexts());
return $state;
}

Expand Down
17 changes: 16 additions & 1 deletion src/Entity/Embargo.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
* "html" = "Drupal\Core\Entity\Routing\AdminHtmlRouteProvider"
* },
* },
* list_cache_tags = { "node_list", "media_list", "file_list" },
* list_cache_contexts = { "ip.embargo_range", "user" },
* list_cache_tags = { "embargo_list" },
* base_table = "embargo",
* admin_permission = "administer embargo",
* entity_keys = {
Expand Down Expand Up @@ -450,4 +451,18 @@ public function ipIsExempt(string $ip): bool {
return $exempt_ips && $exempt_ips->withinRanges($ip);
}

/**
* {@inheritdoc}
*/
protected function getListCacheTagsToInvalidate() : array {
return array_merge(
parent::getListCacheTagsToInvalidate(),
[
'node_list',
'media_list',
'file_list',
]
);
}

}

0 comments on commit 63d0178

Please sign in to comment.