3 namespace Drupal\memcache\Driver;
6 * Class MemcachedDriver.
8 class MemcachedDriver extends DriverBase {
13 public function set($key, $value, $exp = 0, $flag = FALSE) {
14 $collect_stats = $this->statsInit();
16 $full_key = $this->key($key);
17 $result = $this->memcache->set($full_key, $value, $exp);
20 $this->statsWrite('set', 'cache', [$full_key => (int) $result]);
29 public function add($key, $value, $expire = 0) {
30 $collect_stats = $this->statsInit();
32 $full_key = $this->key($key);
33 $result = $this->memcache->add($full_key, $value, $expire);
36 $this->statsWrite('add', 'cache', [$full_key => (int) $result]);
45 public function getMulti(array $keys) {
46 $collect_stats = $this->statsInit();
51 foreach ($keys as $key => $cid) {
52 $full_key = $this->key($cid);
53 $full_keys[$cid] = $full_key;
56 $multi_stats[$full_key] = FALSE;
60 if (PHP_MAJOR_VERSION === 7) {
61 $results = $this->memcache->getMulti($full_keys, \Memcached::GET_PRESERVE_ORDER);
65 $results = $this->memcache->getMulti($full_keys, $cas_tokens, \Memcached::GET_PRESERVE_ORDER);
68 // If $results is FALSE, convert it to an empty array.
74 foreach ($multi_stats as $key => $value) {
75 $multi_stats[$key] = isset($results[$key]) ? TRUE : FALSE;
79 // Convert the full keys back to the cid.
81 $cid_lookup = array_flip($full_keys);
83 foreach (array_filter($results) as $key => $value) {
84 $cid_results[$cid_lookup[$key]] = $value;
88 $this->statsWrite('getMulti', 'cache', $multi_stats);