class AccessResultCache in Permissions by Term 8.2
Hierarchy
- class \Drupal\permissions_by_term\Cache\AccessResultCache
Expanded class hierarchy of AccessResultCache
1 string reference to 'AccessResultCache'
1 service uses AccessResultCache
File
- src/
Cache/ AccessResultCache.php, line 10
Namespace
Drupal\permissions_by_term\CacheView source
class AccessResultCache {
/**
* The default cache bin.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cache;
public function __construct(CacheBackendInterface $cache) {
$this->cache = $cache;
}
public function setAccessResultsCache(int $accountId, $entityId, AccessResult $accessResult) : void {
$data = \serialize($accessResult);
$cid = 'permissions_by_term:access_result_cache:' . $entityId . ':' . $accountId;
$tags = [
'permissions_by_term:access_result_cache:' . $entityId . ':' . $accountId,
'permissions_by_term:access_result_cache:' . $entityId,
'permissions_by_term:access_result_cache',
];
$tags = Cache::mergeTags($tags, [
$cid,
]);
$this->cache
->set($cid, $data, Cache::PERMANENT, $tags);
$staticCache =& drupal_static(__FUNCTION__ . $cid, NULL);
$staticCache = $data;
}
public function getAccessResultsCache(int $accountId, $entityId) : AccessResult {
$cid = 'permissions_by_term:access_result_cache:' . $entityId . ':' . $accountId;
$staticCache =& drupal_static(__FUNCTION__ . $cid, NULL);
if ($staticCache) {
return \unserialize($staticCache);
}
$result = $this->cache
->get($cid);
$data = \unserialize($result->data);
if (!$data instanceof AccessResult) {
throw new \Exception("Unexpected result from cache. Passed accountId: {$accountId} - passed entityId: {$entityId}");
}
return $data;
}
public function hasAccessResultsCache(int $accountId, $entityId) : bool {
$cid = 'permissions_by_term:access_result_cache:' . $entityId . ':' . $accountId;
$staticCache =& drupal_static(__FUNCTION__ . $cid, NULL);
if ($staticCache) {
$data = \unserialize($staticCache);
if (!$data instanceof AccessResult) {
return FALSE;
}
return TRUE;
}
$result = $this->cache
->get($cid);
if (!isset($result->data)) {
return FALSE;
}
$data = \unserialize($result->data);
if (!$data instanceof AccessResult) {
return FALSE;
}
return TRUE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AccessResultCache:: |
protected | property | The default cache bin. | |
AccessResultCache:: |
public | function | ||
AccessResultCache:: |
public | function | ||
AccessResultCache:: |
public | function | ||
AccessResultCache:: |
public | function |