Changed read and write methods for compatibility with class memcached

The methods of the memcached class have different parameters than the memcache class.
This commit is contained in:
Mathias
2019-05-24 12:08:44 +02:00
committed by GitHub
parent c9f0de05f4
commit 6d8d3b67d8

View File

@@ -42,18 +42,12 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
*/ */
protected function read(array $keys) protected function read(array $keys)
{ {
$_keys = $lookup = array(); $res = array();
foreach ($keys as $k) { foreach ($keys as $key) {
$_k = sha1($k); $k = sha1($key);
$_keys[] = $_k; $res[$key] = $this->memcache->get($k);
$lookup[ $_k ] = $k;
} }
$_res = array(); return $res;
$res = $this->memcache->get($_keys);
foreach ($res as $k => $v) {
$_res[ $lookup[ $k ] ] = $v;
}
return $_res;
} }
/** /**
@@ -68,7 +62,11 @@ class Smarty_CacheResource_Memcache extends Smarty_CacheResource_KeyValueStore
{ {
foreach ($keys as $k => $v) { foreach ($keys as $k => $v) {
$k = sha1($k); $k = sha1($k);
$this->memcache->set($k, $v, 0, $expire); if (class_exists('Memcached')) {
$this->memcache->set($k, $v, $expire);
} else {
$this->memcache->set($k, $v, 0, $expire);
}
} }
return true; return true;
} }