class MemcacheDriver in Memcache API and Integration 8.2
Class MemcacheDriver.
Hierarchy
- class \Drupal\memcache\Driver\DriverBase implements DrupalMemcacheInterface uses LoggerChannelTrait
- class \Drupal\memcache\Driver\MemcacheDriver
Expanded class hierarchy of MemcacheDriver
File
- src/
Driver/ MemcacheDriver.php, line 8
Namespace
Drupal\memcache\DriverView source
class MemcacheDriver extends DriverBase {
/**
* {@inheritdoc}
*/
public function set($key, $value, $exp = 0, $flag = FALSE) {
$collect_stats = $this
->statsInit();
$full_key = $this
->key($key);
$result = $this->memcache
->set($full_key, $value, $flag, $exp);
if ($collect_stats) {
$this
->statsWrite('set', 'cache', [
$full_key => (int) $result,
]);
}
return $result;
}
/**
* {@inheritdoc}
*/
public function add($key, $value, $expire = 0) {
$collect_stats = $this
->statsInit();
$full_key = $this
->key($key);
$result = $this->memcache
->add($full_key, $value, FALSE, $expire);
if ($collect_stats) {
$this
->statsWrite('add', 'cache', [
$full_key => (int) $result,
]);
}
return $result;
}
/**
* {@inheritdoc}
*/
public function getMulti(array $keys) {
$collect_stats = $this
->statsInit();
$multi_stats = [];
$full_keys = [];
foreach ($keys as $key => $cid) {
$full_key = $this
->key($cid);
$full_keys[$cid] = $full_key;
if ($collect_stats) {
$multi_stats[$full_key] = FALSE;
}
}
$results = $this->memcache
->get($full_keys);
// If $results is FALSE, convert it to an empty array.
if (!$results) {
$results = [];
}
if ($collect_stats) {
foreach ($multi_stats as $key => $value) {
$multi_stats[$key] = isset($results[$key]) ? TRUE : FALSE;
}
}
// Convert the full keys back to the cid.
$cid_results = [];
// Order isn't guaranteed, so ensure the return order matches that
// requested. So base the results on the order of the full_keys, as they
// reflect the order of the $cids passed in.
foreach (array_intersect($full_keys, array_keys($results)) as $cid => $full_key) {
$cid_results[$cid] = $results[$full_key];
}
if ($collect_stats) {
$this
->statsWrite('getMulti', 'cache', $multi_stats);
}
return $cid_results;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DriverBase:: |
protected | property | The hash algorithm to pass to hash(). Defaults to 'sha1'. | |
DriverBase:: |
protected | property | The memcache object. | |
DriverBase:: |
protected | property | The prefix memcache key for all keys. | |
DriverBase:: |
protected | property | The memcache config object. | |
DriverBase:: |
protected static | property | Stats for the entire request. | |
DriverBase:: |
public | function |
Deletes an item from Memcache. Overrides DrupalMemcacheInterface:: |
|
DriverBase:: |
public | function |
Immediately invalidates all existing items. Overrides DrupalMemcacheInterface:: |
|
DriverBase:: |
public | function |
Retrieves a value from Memcache. Overrides DrupalMemcacheInterface:: |
|
DriverBase:: |
public | function | Helper function to get the bins. | |
DriverBase:: |
public | function | Helper function to get memcache. | |
DriverBase:: |
public | function | Helper function to get the servers. | |
DriverBase:: |
public | function |
Prepares the memcache key. Overrides DrupalMemcacheInterface:: |
|
DriverBase:: |
public | function | Helper function to get request stats. | |
DriverBase:: |
public | function | Retrieves statistics recorded during memcache operations. | |
DriverBase:: |
protected | function | Helper function to initialize the stats for a memcache operation. | |
DriverBase:: |
public | function | Returns an array of available statistics types. | |
DriverBase:: |
protected | function | Memcache statistics to be displayed at end of page generation. | |
DriverBase:: |
public | function | Constructs a DriverBase object. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MemcacheDriver:: |
public | function |
Add an item to Memcache if it doesn't exist already. Overrides DrupalMemcacheInterface:: |
|
MemcacheDriver:: |
public | function |
Retrieves multiple values from Memcache. Overrides DrupalMemcacheInterface:: |
|
MemcacheDriver:: |
public | function |
Adds an item into memcache. Overrides DrupalMemcacheInterface:: |