From: Eileen McNaughton Date: Sat, 9 Oct 2021 04:29:57 +0000 (+1300) Subject: [Ref] Extract getCacheKey X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=35f5d8915a2ef7e389af3b8c6a447ddb67ae33ac;p=civicrm-core.git [Ref] Extract getCacheKey --- diff --git a/CRM/Core/EntityTokens.php b/CRM/Core/EntityTokens.php index 2d5e5b395a..46a4d53982 100644 --- a/CRM/Core/EntityTokens.php +++ b/CRM/Core/EntityTokens.php @@ -75,10 +75,7 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { */ protected function getTokenMetadata(): array { if (empty($this->tokensMetadata)) { - $cacheKey = __CLASS__ . 'token_metadata' . $this->getApiEntityName() . CRM_Core_Config::domainID() . '_' . CRM_Core_I18n::getLocale(); - if ($this->checkPermissions) { - $cacheKey .= '__' . CRM_Core_Session::getLoggedInContactID(); - } + $cacheKey = $this->getCacheKey(); if (Civi::cache('metadata')->has($cacheKey)) { $this->tokensMetadata = Civi::cache('metadata')->get($cacheKey); } @@ -637,4 +634,17 @@ class CRM_Core_EntityTokens extends AbstractTokenSubscriber { } } + /** + * Get a cache key appropriate to the current usage. + * + * @return string + */ + protected function getCacheKey(): string { + $cacheKey = __CLASS__ . 'token_metadata' . $this->getApiEntityName() . CRM_Core_Config::domainID() . '_' . CRM_Core_I18n::getLocale(); + if ($this->checkPermissions) { + $cacheKey .= '__' . CRM_Core_Session::getLoggedInContactID(); + } + return $cacheKey; + } + }