if (!$mc) {
$mc = new \Memcached("pharext");
$mc->addServer("localhost", 11211);
+ $mc->setOption(\Memcached::OPT_PREFIX_KEY, "$ns:");
}
$this->mc = $mc;
}
- private function key($key) {
- return sprintf("%s:%s", $this->ns, $key);
- }
-
function get($key, Item &$item = null, $update = false) {
- if (!$item = $this->mc->get($this->key($key))) {
+ if (!$item = $this->mc->get($key)) {
return false;
}
if ($item->getLTL() >= 0) {
if ($update) {
$item->setTimestamp();
- $this->mc->set($this->key($key), $item, $item->getTTL() + 60*60*24);
+ $this->mc->set($key, $item, $item->getTTL() + 60*60*24);
}
return true;
}
}
function set($key, Item $item) {
- $this->mc->set($this->key($key), $item, (null !== $item->getTTL()) ? $item->getTTL() + 60*60*24 : 0);
+ $this->mc->set($key, $item, (null !== $item->getTTL()) ? $item->getTTL() + 60*60*24 : 0);
return $this;
}
function del($key) {
- $this->mc->delete($this->key($key));
+ $this->mc->delete($key);
}
}