class KeyValueCache in Permissions by Term 8.2
Hierarchy
- class \Drupal\permissions_by_term\Cache\KeyValueCache
Expanded class hierarchy of KeyValueCache
1 file declares its use of KeyValueCache
- AccessStorage.php in src/
Service/ AccessStorage.php
1 string reference to 'KeyValueCache'
1 service uses KeyValueCache
File
- src/
Cache/ KeyValueCache.php, line 10
Namespace
Drupal\permissions_by_term\CacheView source
class KeyValueCache {
/**
* The default cache bin.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cache;
public function __construct(CacheBackendInterface $cache) {
$this->cache = $cache;
}
public function set(array $data) : void {
$cid = 'permissions_by_term:key_value_cache';
$tags = [
'permissions_by_term:key_value_cache',
];
$tags = Cache::mergeTags($tags, [
$cid,
]);
$this->cache
->set($cid, $data, Cache::PERMANENT, $tags);
$staticCache =& drupal_static(__FUNCTION__ . $cid, NULL);
$staticCache = $data;
}
public function get() : array {
$cid = 'permissions_by_term:key_value_cache';
$staticCache =& drupal_static(__FUNCTION__ . $cid, NULL);
if ($staticCache) {
return $staticCache;
}
$result = $this->cache
->get($cid);
$data = $result->data;
if (!is_array($data)) {
throw new \Exception('Result from cache was not an array.');
}
return $data;
}
public function has() : bool {
$cid = 'permissions_by_term:key_value_cache';
$staticCache =& drupal_static(__FUNCTION__ . $cid, NULL);
if ($staticCache) {
$data = $staticCache;
if (!is_array($data)) {
return FALSE;
}
return TRUE;
}
$result = $this->cache
->get($cid);
if (!isset($result->data)) {
return FALSE;
}
$data = $result->data;
if (!is_array($data)) {
return FALSE;
}
return TRUE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
KeyValueCache:: |
protected | property | The default cache bin. | |
KeyValueCache:: |
public | function | ||
KeyValueCache:: |
public | function | ||
KeyValueCache:: |
public | function | ||
KeyValueCache:: |
public | function |