cache = new Memcached(); $this->prefix = $prefix; return $this; } public function sleepSkip ( $id ) { $skip = !$this->sleepTime($id); if ( $skip ) $this->update($id); return $skip; } public function offsetGet ( $id ) { $value = $this->memcached->get($this->prefix . $id); if ( $value === false && $this->memcached->getResultCode() === Memcached::RES_NOTFOUND ) $value = $this[$id] = time() - $this->period; parent::offsetSet($value); return $value; } public function offsetSet ( $id, $value ) { if ( $this->memcached->set($this->prefix . $id, $value) ) { parent::offsetSet($id, $value); return $value; } throw new Exception('Memcached error ! Cannot set value !'); } public function offsetUnset ( $id ) { parent::offsetUnset($id); $this->memcached->delete($this->prefix . $id); } public function offsetExists ( $id ) { $value = $this->memcached->get($this->prefix . $id); if ( $value === false && $this->memcached->getResultCode() === Memcached::RES_NOTFOUND ) return false; return true; } } ?>