3 namespace Drupal\memcache\Driver;
6 * Class MemcacheDriver.
8 class MemcacheDriver 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, $flag, $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, FALSE, $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 $results = $this->memcache->get($full_keys);
62 // If $results is FALSE, convert it to an empty array.
68 foreach ($multi_stats as $key => $value) {
69 $multi_stats[$key] = isset($results[$key]) ? TRUE : FALSE;
73 // Convert the full keys back to the cid.
76 // Order isn't guaranteed, so ensure the return order matches that
77 // requested. So base the results on the order of the full_keys, as they
78 // reflect the order of the $cids passed in.
79 foreach (array_intersect($full_keys, array_keys($results)) as $cid => $full_key) {
80 $cid_results[$cid] = $results[$full_key];
84 $this->statsWrite('getMulti', 'cache', $multi_stats);