3 namespace app\Github\Storage
;
5 use app\Github\Storage
;
7 class Memcache
implements Storage
12 function __construct($ns = "github", \Memcached
$mc = null) {
15 $mc = new \
Memcached("pharext");
16 $mc->addServer("localhost", 11211);
21 private function key($key) {
22 return sprintf("%s:%s", $this->ns
, $key);
25 function get($key, Item
&$item = null, $update = false) {
26 if (!$item = $this->mc
->get($this->key($key))) {
34 if (null === $item->getTTL()) {
37 if ($item->getLTL() >= 0) {
39 $item->setTimestamp();
40 $this->mc
->set($this->key($key), $item, $item->getTTL() +
60*60*24);
47 function set($key, Item
$item) {
48 $this->mc
->set($this->key($key), $item, (null !== $item->getTTL()) ?
$item->getTTL() +
60*60*24 : 0);
53 $this->mc
->delete($this->key($key));