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);
}
}
$rd = new \Redis();
$rd->open("localhost");
$rd->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP);
+ $rd->setOption(\Redis::OPT_PREFIX, "$ns:");
}
$this->rd = $rd;
}
- private function key($key) {
- return sprintf("%s:%s", $this->ns, $key);
- }
-
function get($key, Item &$item = null, $update = false) {
- if (!$item = $this->rd->get($this->key($key))) {
+ if (!$item = $this->rd->get($key)) {
return false;
}
if ($item->getLTL() >= 0) {
if ($update) {
$item->setTimestamp();
- $this->rd->setex($this->key($key), $item->getTTL() + 60*60*24, $item);
+ $this->rd->setex($key, $item->getTTL() + 60*60*24, $item);
}
return true;
}
function set($key, Item $item) {
if (null === $item->getTTL()) {
- $this->rd->set($this->key($key), $item);
+ $this->rd->set($key, $item);
} else {
- $this->rd->setex($this->key($key), $item->getTTL() + 60*60*24, $item);
+ $this->rd->setex($key, $item->getTTL() + 60*60*24, $item);
}
return $this;
}
function del($key) {
- $this->rd->delete($this->key($key));
+ $this->rd->delete($key);
}
}
$config->$basic->auth->toArray(),
0);
}
+ $logger = new Github\Logger($config);
+
// FIXME: configure through app.ini
try {
$cache = new Github\Storage\Redis("gh-cache");
} catch (\Exception $ex) {
- try {
- $cache = new Github\Storage\Memcache("gh-cache");
- } catch (\Exception $ex) {
- $cache = null;
- }
+ /* Memcached won't throw an exception */
+ $cache = new Github\Storage\Memcache("gh-cache");
}
return new Github\API(
$config->github
- ,new Github\Logger($config)
+ ,$logger
,new Github\Storage\Session("gh-tokens")
,$cache
);