class CacheApcu in Drupal driver for SQL Server and SQL Azure 8.2
Apcu implementation for the in-memory fast cache. Use this for very frequently used cache items.
Hierarchy
- class \Drupal\Driver\Database\sqlsrv\Component\CacheApcu implements CacheInterface
Expanded class hierarchy of CacheApcu
File
- drivers/
lib/ Drupal/ Driver/ Database/ sqlsrv/ Component/ CacheApcu.php, line 9
Namespace
Drupal\Driver\Database\sqlsrv\ComponentView source
class CacheApcu implements CacheInterface {
private $prefix = null;
/**
* This cache stores everything in-memory during the
* lifetime of this request.
*
* @var array
*/
private $data = [];
/**
* Serializer to use.
*
* @var SerializerInterface
*/
private $serializer = null;
public function __construct($prefix) {
$this->prefix = $prefix;
// Try to use a serializer...
if (function_exists('igbinary_serialize')) {
$this->serializer = new SerializerIgbinary();
}
else {
$this->serializer = new SerializerPhp();
}
}
/**
* {@inheritdoc}
*/
public function Set($cid, $data) {
$cache = new \stdClass();
$cache->data = $data;
$cache->serialized = false;
$cache->timestamp = time();
$this->data[$cid] = clone $cache;
apcu_store($this->prefix . ':' . $cid, $cache);
}
/**
* {@inheritdoc}
*/
public function Get($cid) {
if (isset($this->data[$cid])) {
return $this->data[$cid];
}
$success = false;
$result = apcu_fetch($this->prefix . ':' . $cid, $success);
if (!$success) {
return false;
}
if (isset($result->serialized) && $result->serialized) {
$result->data = $this->serializer
->unserialize($result->data);
}
$this->data[$cid] = $result;
return $result;
}
/**
* {@inheritdoc}
*/
public function Clear($cid) {
apcu_delete($this->prefix . ':' . $cid);
unset($this->data[$cid]);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheApcu:: |
private | property | This cache stores everything in-memory during the lifetime of this request. | |
CacheApcu:: |
private | property | ||
CacheApcu:: |
private | property | Serializer to use. | |
CacheApcu:: |
public | function |
Clear a cache item. Overrides CacheInterface:: |
|
CacheApcu:: |
public | function |
Get a cache item. Overrides CacheInterface:: |
|
CacheApcu:: |
public | function |
Set a cache item. Overrides CacheInterface:: |
|
CacheApcu:: |
public | function |