本文整理汇总了PHP中Memcached::touch方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcached::touch方法的具体用法?PHP Memcached::touch怎么用?PHP Memcached::touch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcached
的用法示例。
在下文中一共展示了Memcached::touch方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: touchKeys
/**
* 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;
}
示例2: write
/**
* 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();
}
示例3: touch
/**
* 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);
}
示例4: touch
/**
* 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);
}
示例5: write
/**
* 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']);
}
示例6: write
/**
* 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;
}
示例7: testTouchSuccess
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();
}
示例8: Memcached
<?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;
示例9: changeTTL
public function changeTTL($key, $exptime = 0)
{
return $this->client->touch($this->validateKeyEncoding($key), $this->fixExpiry($exptime));
}
示例10: touch
/**
* @param $key
* @param $expiration
*/
public function touch($key, $expiration)
{
$this->memcached->touch($key, $expiration);
}
示例11: Memcached
<?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";
示例12: touch
/**
* @inheritdoc
*/
public function touch($key, $expire = 0)
{
return $this->storage->touch($this->prepareKey($key), $expire);
}
示例13: touch
/**
* @inheritdoc
*/
public function touch($key, $expiration)
{
$key = $this->prefix . $key;
return parent::touch($key, $expiration);
}
示例14: touch
/**
* 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);
}