// example:
// get_cache('foo');
// get_cache(['foo', 'bar']);
function get_cache($keys) {
static $cache = [];
static $memcached;
$keys = (array)$keys;
$result = $missing = [];
foreach ($keys as $key) {
if (isset($cache[$key])) {
$result[$key] = $cache[$key];
} else {
$missing[] = $key;
}
}
if (!$missing) {
return $result;
}
if (!$memcached) {
$memcached = new Memcached;
}
$mresult = $memcached->getMulti($missing);
if ($mresult) {
foreach ($mresult as $key => $value) {
$result[$key] = $cache[$key] = $value;
}
}
return $result;
}