public function testTouch() { $this->rediska->set('test', array('aaa', time(), 100)); $this->rediska->expire('test', 100); $reply = $this->cache->touch('test', 200); $this->assertTrue($reply); $lifetime = $this->rediska->getLifetime('test'); $this->assertTrue($lifetime > 290); $values = $this->rediska->get('test'); $this->assertEquals(300, $values[2]); }
/** * Write session data * * @param string $id * @param string $data * @return boolean */ public function write($id, $data) { $this->_set[] = $id; $reply = $this->_rediska->set($this->_getKeyName($id), $data); if ($reply) { $this->_rediska->expire($this->_getKeyName($id), $this->_options['lifetime']); } return $reply; }
/** * Give (if possible) an extra lifetime to the given cache id * * @param string $id cache id * @param int $extraLifetime * @return boolean true if ok */ public function touch($id, $extraLifetime) { $tmp = $this->_rediska->get($id); if (is_array($tmp)) { $data = $tmp[0]; $mtime = $tmp[1]; if (!isset($tmp[2])) { // because this record is only with 1.7 release // if old cache records are still there... return false; } $lifetime = $tmp[2]; $newLifetime = $lifetime - (time() - $mtime) + $extraLifetime; if ($newLifetime <= 0) { return false; } $result = $this->_rediska->set($id, array($data, time(), $newLifetime)); if ($result) { $this->_rediska->expire($id, $newLifetime); } return $result; } return false; }
protected function _write() { return $this->_rediska->expire($this->id(), $this->_lifetime()); }