MemcacheDriver.php in Memcache API and Integration 8.2
File
src/Driver/MemcacheDriver.php
View source
<?php
namespace Drupal\memcache\Driver;
class MemcacheDriver extends DriverBase {
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;
}
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;
}
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) {
$results = [];
}
if ($collect_stats) {
foreach ($multi_stats as $key => $value) {
$multi_stats[$key] = isset($results[$key]) ? TRUE : FALSE;
}
}
$cid_results = [];
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;
}
}