X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fmemcache%2Fsrc%2FDriver%2FMemcachedDriver.php;fp=web%2Fmodules%2Fcontrib%2Fmemcache%2Fsrc%2FDriver%2FMemcachedDriver.php;h=0e8e67d66a94f9e24a87685333e324e711e95a6e;hp=0000000000000000000000000000000000000000;hb=059867c3f96750652c80f39e44c442a58c2549ee;hpb=f8fc16ae6b862bef59baaad5d051dd37b7ff11b2 diff --git a/web/modules/contrib/memcache/src/Driver/MemcachedDriver.php b/web/modules/contrib/memcache/src/Driver/MemcachedDriver.php new file mode 100755 index 000000000..0e8e67d66 --- /dev/null +++ b/web/modules/contrib/memcache/src/Driver/MemcachedDriver.php @@ -0,0 +1,94 @@ +statsInit(); + + $full_key = $this->key($key); + $result = $this->memcache->set($full_key, $value, $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, $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; + } + } + + if (PHP_MAJOR_VERSION === 7) { + $results = $this->memcache->getMulti($full_keys, \Memcached::GET_PRESERVE_ORDER); + } + else { + $cas_tokens = NULL; + $results = $this->memcache->getMulti($full_keys, $cas_tokens, \Memcached::GET_PRESERVE_ORDER); + } + + // 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 = []; + $cid_lookup = array_flip($full_keys); + + foreach (array_filter($results) as $key => $value) { + $cid_results[$cid_lookup[$key]] = $value; + } + + if ($collect_stats) { + $this->statsWrite('getMulti', 'cache', $multi_stats); + } + + return $cid_results; + } + +}