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, &$val = null, &$ltl = null, $update = false) {
26 if (!$item = $this->mc
->get($this->key($key))) {
38 $ltl = $ttl - ($now - $set);
42 $this->mc
->set($this->key($key), $item, $ttl +
60*60*24);
49 function set($key, $val, $ttl = null) {
50 $item = new Memcache\
Item([
53 "time" => isset($ttl) ?
time() : null
55 $this->mc
->set($this->key($key), $item, isset($ttl) ?
$ttl +
60*60*24 : 0);
60 $this->mc
->delete($this->key($key));
64 namespace app\Github\Storage\Memcache
;
72 function __construct(array $data) {
73 foreach ($data as $key => $val) {