class CacheWincache in Drupal driver for SQL Server and SQL Azure 8.2
Wincache implementation for the in-memory fast cache. Use this for very frequently used cache items.
Hierarchy
- class \Drupal\Driver\Database\sqlsrv\Component\CacheWincache implements CacheInterface
Expanded class hierarchy of CacheWincache
File
- drivers/
lib/ Drupal/ Driver/ Database/ sqlsrv/ Component/ CacheWincache.php, line 9
Namespace
Drupal\Driver\Database\sqlsrv\ComponentView source
class CacheWincache 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;
wincache_ucache_set($this->prefix . ':' . $cid, $cache);
}
/**
* {@inheritdoc}
*/
public function Get($cid) {
if (isset($this->data[$cid])) {
return $this->data[$cid];
}
$success = false;
$result = wincache_ucache_get($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) {
if (empty($cid)) {
$info = wincache_ucache_info();
foreach ($info['ucache_entries'] as $entry) {
$key = $entry['key_name'];
if (strpos($key, $this->prefix . ':') === 0) {
wincache_ucache_delete($key);
unset($this->data[$key]);
}
}
}
else {
wincache_ucache_delete($this->prefix . ':' . $cid);
unset($this->data[$cid]);
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheWincache:: |
private | property | This cache stores everything in-memory during the lifetime of this request. | |
CacheWincache:: |
private | property | ||
CacheWincache:: |
private | property | Serializer to use. | |
CacheWincache:: |
public | function |
Clear a cache item. Overrides CacheInterface:: |
|
CacheWincache:: |
public | function |
Get a cache item. Overrides CacheInterface:: |
|
CacheWincache:: |
public | function |
Set a cache item. Overrides CacheInterface:: |
|
CacheWincache:: |
public | function |