trait ChainedStorageTrait in Supercache 8
Same name and namespace in other branches
- 2.0.x src/KeyValueStore/ChainedStorageTrait.php \Drupal\supercache\KeyValueStore\ChainedStorageTrait
Hierarchy
- trait \Drupal\supercache\KeyValueStore\ChainedStorageTrait
File
- src/
KeyValueStore/ ChainedStorageTrait.php, line 18
Namespace
Drupal\supercache\KeyValueStoreView source
trait ChainedStorageTrait {
/**
* The cache backend.
*
* @var CacheBackendInterface
*/
protected $cache;
/**
* Special value stored in the cache layer
* to identify missing items in the persistent
* cache.
*
* @var string
*/
protected $EMPTY_VALUE = '@@empty';
/**
* To prevent database lookups we store a special 'empty'
* object.
*
* @param array $requested
* The requested set of keys from getMultiple().
*
* @param array $obtained
* The effectively obtained key-value pairs.
*
*/
protected function populateMissingValuesLocal($requested, $obtained) {
$missing = array_diff_key(array_flip($requested), $obtained);
foreach ($missing as $key => $value) {
$missing[$key] = $this->EMPTY_VALUE;
}
$this->cache
->setMultiple($this
->KeyValueToCache($missing));
}
/**
* Converts an array of KeyValues to a cache compatible array.
*
* @param array $items
* Key/Value pair items to store.
* @param array $items
* Expiration times for the items.
* @return array
*/
protected function KeyValueToCache(array $items, array $expirations = []) {
$result = array();
foreach ($items as $key => $value) {
$result[$key] = array(
'data' => $value,
'expire' => isset($expirations[$key]) ? $expirations[$key] : CacheBackendInterface::CACHE_PERMANENT,
'tags' => array(),
);
}
return $result;
}
/**
* Converts a cache array to a KeyValue array.
*
* @param array $items
* @return array
*/
protected function CacheToKeyValue(array $items) {
$result = array();
foreach ($items as $key => $value) {
if (is_object($value) && $value->data !== $this->EMPTY_VALUE) {
$result[$key] = $value->data;
}
}
return $result;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ChainedStorageTrait:: |
protected | property | The cache backend. | |
ChainedStorageTrait:: |
protected | property | Special value stored in the cache layer to identify missing items in the persistent cache. | |
ChainedStorageTrait:: |
protected | function | Converts a cache array to a KeyValue array. | |
ChainedStorageTrait:: |
protected | function | Converts an array of KeyValues to a cache compatible array. | |
ChainedStorageTrait:: |
protected | function | To prevent database lookups we store a special 'empty' object. |