Skip to content

Commit

Permalink
[Ref] Extract getCacheKey
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Oct 9, 2021
1 parent ef5cf85 commit 23767da
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions CRM/Core/EntityTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ public function registerTokens(TokenRegisterEvent $e) {
*/
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);
}
Expand Down Expand Up @@ -625,4 +622,17 @@ public function getActiveTokens(TokenValueEvent $e) {
return array_intersect($messageTokens[$this->entity], array_keys($this->getTokenMetadata()));
}

/**
* 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;
}

}

0 comments on commit 23767da

Please sign in to comment.