本文整理汇总了PHP中Memcached::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcached::get方法的具体用法?PHP Memcached::get怎么用?PHP Memcached::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcached
的用法示例。
在下文中一共展示了Memcached::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exists
/**
* {@inheritdoc}
*/
public function exists()
{
if (false === $this->memcached->get($this->storeId)) {
return MemcachedClient::RES_SUCCESS === $this->memcached->getResultCode();
}
return true;
}
示例2: get
public function get($id)
{
if (($value = $this->memcached->get($id)) === false) {
return null;
}
return $value;
}
示例3: read
/**
* Чтение массива из кеша
* @param string $cache_file кешируемый файл
* @param int $mytime время жизни кеш файла, отличное от глобальных настроек
* @return mixed массив, если файл кеширован и не требует обновления,
* false - если необходимо обновить/создать
*/
public function read($cache_file, $mytime = false)
{
$cache_file = validpath($cache_file);
if (!$cache_file || !$this->state) {
return false;
}
$this->cache_files[] = $cache_file;
$f = ROOT . 'include/cache/' . $cache_file . '.html';
$my_array = array();
if ($this->m) {
$my_array = $this->m->get($cache_file);
} elseif (file_exists($f)) {
$contents = file_get_contents($f);
$my_array = unserialize($contents);
}
if (!$my_array) {
return false;
}
$array = (array) $my_array[0];
$time = $my_array['!_cache_time_'];
$delay = $mytime ? $mytime : $this->time * 3600;
if ($time < time() - $delay) {
if ($this->m) {
$this->m->delete($cache_file);
}
return false;
}
$this->pop_readed();
// Ибо уже кешировано
return $array;
}
示例4: read
/**
* Read an object from memcached if it exists,
* otherwise load the object from the database and then cache it
* @param mixed $pkValue Primary key value
* @param integer|boolean $cache Number of seconds to cache the object for
* 0 = cache never expires, FALSE = do not cache
* @return boolean
*/
public function read($pkValue = FALSE, $cache = FALSE)
{
// If we're not caching or there is no memcached object just call parent
if ($cache === FALSE || !$this->memcached instanceof \Memcached) {
return parent::read($pkValue);
}
// If there is a key value passed set it
if ($pkValue !== FALSE) {
$this->iset(static::$pk, $pkValue);
}
// Load memcached object attributres
$obj = $this->memcached->get($this->getMemcachedID());
// If the object is not cached, load and cache it
if ($obj === FALSE) {
// Read object
if (parent::read($pkValue) === FALSE) {
return FALSE;
}
// Cache object attributes
$this->memcached->set($this->getMemcachedID(), $this->getCacheAttributes(), $cache);
} else {
$this->setCacheAttributes($obj);
}
// Return
return TRUE;
}
示例5: get
/**
* @return mixed
*/
public function get()
{
if (isset(static::$cache[$this->key])) {
return static::$cache[$this->key];
}
return $this->memcached->get($this->key);
}
示例6: get
/**
* Retrieve an item from the cache by key.
*
* @param string|array $key
* @return mixed
*/
public function get($key)
{
$value = $this->memcached->get($this->prefix . $key);
if ($this->memcached->getResultCode() == 0) {
return $value;
}
}
示例7: _exists
/**
* @see Cache::_exists()
*/
protected function _exists($key)
{
if (!$this->is_connected) {
return false;
}
return $this->memcached->get($key) !== false;
}
示例8: release
/**
* 解锁
* @param unknown $key
*/
public function release($key)
{
$key = $this->prefix . $key;
if ($this->memcached->get($key) === $this->Identifier) {
$this->memcached->delete($key);
}
}
示例9: get
/**
* @param $key
* @return mixed
*/
public function get($key)
{
if (!is_null($this->memcache)) {
return $this->memcache->get($key);
}
return false;
}
示例10: Get
/**
* Gets an item from the cache
*
* @param string $key cache key
* @return mixed cached object or false if not found
*/
public function Get($key)
{
if (empty($key)) {
return false;
}
return $this->memcache->get($key);
}
示例11: get
/**
* Get a value from cache
*
* @param string $p_sKey The Key
* @return mixed
*/
function get($p_sKey)
{
if ($this->_serverAdded === false) {
$this->addServer('localhost');
}
return $this->_handler->get($p_sKey);
}
示例12: load
/**
* {@inheritdoc}
*/
public function load()
{
$contents = $this->memcached->get($this->key);
if ($contents) {
$this->setFromStorage($contents);
}
}
示例13: cacheStrategyOnce
/**
* 通过加锁机制在cache失效时并发时只透传一个请求到后端子系统
* @param $method string 方法名
* @param $params array 参数列表
* @param $key string 缓存key
*/
public static function cacheStrategyOnce($method, $params, $key, $expire = 100)
{
// 做法相似,只是需要把概率判断的算法换成使用锁保证高并发请求时严格只有一个请求透传到后端系统
$csfKey = self::getCSTKey($key, 1);
$lockKey = self::getCSTLockKey($key, 1);
$memcached = new Memcached();
$memcached->addServer('127.0.0.1', 11211);
$value = $memcached->get($csfKey);
if (!empty($value) && !empty($value['data']) && !empty($value['doubleExpire'])) {
$doubleExpire = $value['doubleExpire'];
if (time() <= $doubleExpire - $expire) {
// cache还在[start, start + expire]时间内仍有效,无需请求后端
return $value['data'];
}
$isLock = $memcached->get($lockKey);
if (!empty($lockKey)) {
// 有锁,表示当前已有请求到后端去读取最新数据并更新cache;
return $value['data'];
}
}
// cache已过期或者无锁,到后台实时请求并更新cache
$ret = $memcached->set($lockKey, 1, 1);
$data = self::$method($params);
if (isset($data['resultCode']) && $data['resultCode'] == 0) {
unset($data['resultCode']);
$doubleExpire = time() + 2 * $expire;
$value = array('data' => $data, 'doubleExpire' => $doubleExpire);
$ret = $memcached->set($csfKey, $value, $doubleExpire);
}
$ret = $memcached->delete($lockKey, 1);
return $data;
}
示例14: load
/**
* Loads item by cache key.
*
* @param string $key
* @return mixed
*
* @throws Ejsmont\CircuitBreaker\Storage\StorageException if storage error occurs, handler can not be used
*/
protected function load($key)
{
try {
return $this->memcached->get($key);
} catch (\Exception $e) {
throw new StorageException("Failed to load memcached key: {$key}", 1, $e);
}
}
示例15: testInvalidate
/**
* @group memcached
*/
public function testInvalidate()
{
$mc = new MemcachedCacheBackend();
$mc->addServer(new MemcachedServer(self::TEST_MEMCACHE_SERVER));
$mc->invalidate('test');
$this->assertFalse($this->memcache->get('test'));
$this->assertEquals(\Memcached::RES_NOTFOUND, $this->memcache->getResultCode());
}