/** * renew caches * @param array $keys * @return bool */ public function touchKeys($keys) { foreach ($keys as $key) { if (!$this->m->touch($key, 3600 * 24)) { return false; } } return true; }
/** * Write * * Writes (create / update) session data * * @param string $session_id Session ID * @param string $session_data Serialized session data * @return bool */ public function write($session_id, $session_data) { if (!isset($this->_memcached)) { return $this->_fail(); } elseif ($session_id !== $this->_session_id) { if (!$this->_release_lock() or !$this->_get_lock($session_id)) { return $this->_fail(); } $this->_fingerprint = md5(''); $this->_session_id = $session_id; } if (isset($this->_lock_key)) { $key = $this->_key_prefix . $session_id; $this->_memcached->replace($this->_lock_key, time(), 300); if ($this->_fingerprint !== ($fingerprint = md5($session_data))) { if ($this->_memcached->replace($key, $session_data, $this->_config['expiration']) or $this->_memcached->getResultCode() === Memcached::RES_NOTFOUND && $this->_memcached->set($key, $session_data, $this->_config['expiration'])) { $this->_fingerprint = $fingerprint; return $this->_success; } return $this->_fail(); } if ($this->_memcached->touch($key, $this->_config['expiration']) or $this->_memcached->getResultCode() === Memcached::RES_NOTFOUND && $this->_memcached->set($key, $session_data, $this->_config['expiration'])) { return $this->_success; } } return $this->_fail(); }
/** * Sets a new expire time for an existing key * * @param string $cache_id * @param int $newexpiration * @return bool */ public function touch($cache_id, $newexpiration = null) { if (is_null($newexpiration)) { return false; } return $this->memcache->touch($cache_id, $newexpiration); }
/** * Touch a cache key (i.e., new expiration). * * @since 151216 Memcached utilities. * * @param string $primary_key Primary key. * @param string|int $sub_key Sub-key to touch. * @param int $expires_after Expires after (in seconds). * * @return bool True on success. */ public function touch(string $primary_key, $sub_key, int $expires_after) : bool { if (!$this->Pool) { return false; // Not possible. } $time = time(); $expires_after = max(0, $expires_after); $expires = $expires_after ? $time + $expires_after : 0; if (!($key = $this->key($primary_key, $sub_key))) { return false; // Fail; e.g., race condition. } return $this->Pool->touch($key, $expires); }
/** * Write * * Writes (create / update) session data * * @param string $session_id Session ID * @param string $session_data Serialized session data * @return bool */ public function write($session_id, $session_data) { if (!isset($this->_memcached)) { return FALSE; } elseif ($session_id !== $this->_session_id) { /* if ( ! $this->_release_lock() OR ! $this->_get_lock($session_id)) { return FALSE; }*/ $this->_fingerprint = md5(''); $this->_session_id = $session_id; } /* if (isset($this->_lock_key)) { $this->_memcached->replace($this->_lock_key, time(), 300); if ($this->_fingerprint !== ($fingerprint = md5($session_data))) { if ($this->_memcached->set($this->_key_prefix.$session_id, $session_data, $this->_config['expiration'])) { $this->_fingerprint = $fingerprint; return TRUE; } return FALSE; } return $this->_memcached->touch($this->_key_prefix.$session_id, $this->_config['expiration']); }*/ $this->_memcached->replace($this->_lock_key, time(), 300); if ($this->_fingerprint !== ($fingerprint = md5($session_data))) { if ($this->_memcached->set($this->_key_prefix . $session_id, $session_data, $this->_config['expiration'])) { $this->_fingerprint = $fingerprint; return TRUE; } return FALSE; } return $this->_memcached->touch($this->_key_prefix . $session_id, $this->_config['expiration']); }
/** * Write * * Writes (create / update) session data * * @param string $session_id Session ID * @param string $session_data Serialized session data * * @return bool */ public function write($session_id, $session_data) { if (!isset($this->memcached)) { return false; } elseif ($session_id !== $this->sessionID) { if (!$this->releaseLock() || !$this->lockSession($session_id)) { return false; } $this->fingerprint = md5(''); $this->sessionID = $session_id; } if (isset($this->lockKey)) { $this->memcached->replace($this->lockKey, time(), 300); if ($this->fingerprint !== ($fingerprint = md5($session_data))) { if ($this->memcached->set($this->keyPrefix . $session_id, $session_data, $this->sessionExpiration)) { $this->_fingerprint = $fingerprint; return true; } return false; } return $this->memcached->touch($this->keyPrefix . $session_id, $this->sessionExpiration); } return false; }
public function testTouchSuccess() { $request = new MemcacheGetRequest(); $request->addKey("key"); $request->setForCas(true); $response = new MemcacheGetResponse(); $item = $response->addItem(); $item->setKey("key"); $item->setValue("value"); $item->setFlags(0); // string. $item->setCasId(123456); $this->apiProxyMock->expectCall('memcache', 'Get', $request, $response); $request = new MemcacheSetRequest(); $item = $request->addItem(); $item->setKey("key"); $item->setValue("value"); $item->setFlags(0); // string $item->setCasId(123456); $item->setSetPolicy(SetPolicy::CAS); $item->setExpirationTime(999); $response = new MemcacheSetResponse(); $response->addSetStatus(SetStatusCode::STORED); $this->apiProxyMock->expectCall('memcache', 'Set', $request, $response); $memcached = new Memcached(); $this->assertTrue($memcached->touch("key", 999)); $this->apiProxyMock->verify(); }
<?php $m = new Memcached(); $m->setOption(Memcached::OPT_BINARY_PROTOCOL, true); $m->addServer('localhost', '11211'); $key = uniqid('touch_binary'); $m->set($key, 'test', time() + 86400); $m->get($key); echo "GET: " . $m->getResultMessage() . PHP_EOL; $m->touch($key, time() + 86400); echo "TOUCH: " . $m->getResultMessage() . PHP_EOL; $m->touch($key, time() + 86400); echo "TOUCH: " . $m->getResultMessage() . PHP_EOL; $m->get($key); echo "GET: " . $m->getResultMessage() . PHP_EOL; $m->get($key); echo "GET: " . $m->getResultMessage() . PHP_EOL; echo "DONE" . PHP_EOL;
public function changeTTL($key, $exptime = 0) { return $this->client->touch($this->validateKeyEncoding($key), $this->fixExpiry($exptime)); }
/** * @param $key * @param $expiration */ public function touch($key, $expiration) { $this->memcached->touch($key, $expiration); }
<?php $mc = new Memcached(); $mc->addServer('localhost', '11211'); $key = uniqid("this_does_not_exist_"); $mc->touch($key, 5); var_dump($mc->getResultCode() == Memcached::RES_NOTFOUND); $mc->set($key, 1, 5); $mc->set($key, 1, 5); var_dump($mc->getResultCode() == Memcached::RES_SUCCESS); echo "OK\n";
/** * @inheritdoc */ public function touch($key, $expire = 0) { return $this->storage->touch($this->prepareKey($key), $expire); }
/** * @inheritdoc */ public function touch($key, $expiration) { $key = $this->prefix . $key; return parent::touch($key, $expiration); }
/** * Wrap the `touch()` method for php-memcached/libmemcached installations * that do not support it (< 1.7) * * @param string $key Key * @param integer $expriy Number of seconds until the item expires. * @return boolean Success or not. */ function touch($key, $expriy = 0) { if (!method_exists("Memcached", "touch")) { trigger_error(E_WARNING, "Your memcached extension does not support the touch() method."); return false; } return parent::touch($key, $expiry); }