本文整理汇总了PHP中Memcache::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcache::get方法的具体用法?PHP Memcache::get怎么用?PHP Memcache::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcache
的用法示例。
在下文中一共展示了Memcache::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: afterQuery
public function afterQuery(Atomik_Model_Builder $builder, Atomik_Model_Modelset $modelSet)
{
$modelName = $builder->name;
$primaryKeyName = $builder->getPrimaryKeyField()->name;
$manager = $builder->getManager();
$db = $manager->getDbInstance();
$rows = array();
$dataQuery = $db->q()->select()
->from($builder->tableName)
->where(array($primaryKeyName => null));
foreach ($modelSet as $row) {
$primaryKey = $row[$primaryKeyName];
$key = $modelName . ':' . $primaryKey;
if (($cached = $this->_memcache->get($key)) !== false) {
// cache hit
$rows[] = $cached;
continue;
}
$data = $dataQuery->setParams(array($primaryKey))->execute()->fetch();
$this->_memcache->set($key, $data);
$rows[] = $data;
}
$modelSet->setData($rows);
}
示例3: _exists
/**
* @see Cache::_exists()
*/
protected function _exists($key)
{
if (!$this->is_connected) {
return false;
}
return $this->memcache->get($key) !== false;
}
示例4: get
public function get($key)
{
if (null === $this->memcache) {
$this->connect();
}
return $this->memcache->get($key);
}
示例5: get
/**
* get cache item with given key
*
* @param string $key
* @return string|array
*/
public function get($key)
{
if (empty($key)) {
throw new InvalidArgumentException("\$key is empty");
}
return $this->memcache->get($key);
}
示例6: read
/**
* Read from cache.
* @param string key
* @return mixed|NULL
*/
public function read($key)
{
$key = $this->prefix . $key;
$meta = $this->memcache->get($key);
if (!$meta) {
return NULL;
}
// meta structure:
// array(
// data => stored data
// delta => relative (sliding) expiration
// callbacks => array of callbacks (function, args)
// )
// verify dependencies
if (!empty($meta[self::META_CALLBACKS]) && !NCache::checkCallbacks($meta[self::META_CALLBACKS])) {
$this->memcache->delete($key, 0);
return NULL;
}
if (!empty($meta[self::META_DELTA])) {
$this->memcache->replace($key, $meta, 0, $meta[self::META_DELTA] + time());
}
return $meta[self::META_DATA];
}
示例7: _updateValue
/**
* Write a line to the logfile.
* @param String $line
*/
protected function _updateValue($message, $keyPostfix = "")
{
$key = $this->_getKey($keyPostfix);
$value = $this->_memcache->get($key);
$value .= self::VALUE_SEPARATOR . $message;
$this->_memcache->set($key, $value, null, $this->_expiry);
}
示例8: checkCache
function checkCache($check = 0, $in, $out, $set = 0)
{
$inOut = 'inOut_' . $in . '_' . $out;
$memcache_obj = new Memcache();
$memcache_obj->connect('127.0.0.1', 11211) or die("Could not connect");
if ($check === 1) {
$available = $memcache_obj->get($inOut);
if (!$available) {
$set = $this->superfastCheck(1, $in, $out);
$memcache_obj->set($inOut, $set, false, 324);
$available = $memcache_obj->get($inOut);
}
} elseif ($check === 2) {
$memcache_obj->flush();
} else {
$set = $this->superfastCheck($in, $out);
//var_dump($set);
$memcache_obj->set($inOut, $set, false, 324);
//echo $inOut;
$available = $memcache_obj->get($inOut);
//var_dump($memcache_obj->getStats());
}
//var_dump($available);
$memcache_obj->close();
return $available;
}
示例9: read
/**
* @param string $id - session id, must be valid hash
* @return string
*/
public static function read($id)
{
if (!self::isConnected() || !self::isValidId($id)) {
return "";
}
$sid = self::getPrefix();
if (!self::$isReadOnly) {
$lockTimeout = 55;
//TODO: add setting
$lockWait = 59000000;
//micro seconds = 60 seconds TODO: add setting
$waitStep = 100;
while (!self::$connection->add($sid . $id . ".lock", 1, 0, $lockTimeout)) {
usleep($waitStep);
$lockWait -= $waitStep;
if ($lockWait < 0) {
CSecuritySession::triggerFatalError('Unable to get session lock within 60 seconds.');
}
if ($waitStep < 1000000) {
$waitStep *= 2;
}
}
}
self::$sessionId = $id;
$res = self::$connection->get($sid . $id);
if ($res === false) {
$res = "";
}
return $res;
}
示例10: __construct
/**
* Creates a new MemcacheAdapter object.
*/
private function __construct()
{
if (!class_exists('Memcache')) {
throw new SystemException('memcache support is not enabled.');
}
// init memcache
$this->memcache = new Memcache();
// add servers
$servers = explode("\n", StringUtil::unifyNewlines(CACHE_SOURCE_MEMCACHE_HOST));
foreach ($servers as $server) {
$server = StringUtil::trim($server);
if (!empty($server)) {
$host = $server;
$port = 11211;
// default memcache port
// get port
if (strpos($host, ':')) {
$parsedHost = explode(':', $host);
$host = $parsedHost[0];
$port = $parsedHost[1];
}
$this->memcache->addServer($host, $port, CACHE_SOURCE_MEMCACHE_USE_PCONNECT);
}
}
// test connection
$this->memcache->get('testing');
}
示例11: get
public function get($id)
{
if (($value = $this->memcache->get($id)) === false) {
return null;
}
return $value;
}
示例12: get
public function get($key)
{
$status = $this->aerospike->get($this->getKey($key), $record);
if ($status == \Aerospike::OK) {
return $record['bins'];
}
}
示例13: read
/**
* Read values for a set of keys from cache
*
* @param array $keys list of keys to fetch
* @return array list of values with the given keys used as indexes
* @return boolean true on success, false on failure
*/
protected function read(array $keys)
{
$_res = array();
/*
$_keys = $lookup = array();
foreach ($keys as $k) {
$_k = sha1($k);
$_keys[] = $_k;
$lookup[$_k] = $k;
}
$res = $this->phpFastCache->get($_keys);
if(!$res){
return $res;
}
foreach ($res as $k => $v) {
$_res[$lookup[$k]] = $v;
} //*/
foreach ($keys as $k) {
$k = sha1($k);
$_res[$k] = $this->phpFastCache->get($k);
//$_res[$k]=unserialize($_res[$k]);
}
//dump($_res);
return $_res;
}
示例14: run
public function run($request)
{
if (!class_exists('Memcache')) {
$this->msg("Memcache class does not exist. Make sure that the Memcache extension is installed");
}
$host = defined('MEMCACHE_HOST') ? MEMCACHE_HOST : 'localhost';
$port = defined('MEMCACHE_PORT') ? MEMCACHE_PORT : 11211;
$memcache = new Memcache();
$connected = $memcache->connect($host, $port);
if ($connected) {
$this->msg("Server's version: " . $memcache->getVersion());
$result = $memcache->get("key");
if ($result) {
$this->msg("Data found in cache");
} else {
$this->msg("Data not found in cache");
$tmp_object = new stdClass();
$tmp_object->str_attr = "test";
$tmp_object->int_attr = 123;
$tmp_object->time = time();
$tmp_object->date = date('Y-m-d H:i:s');
$tmp_object->arr = array(1, 2, 3);
$memcache->set("key", $tmp_object, false, 10);
}
$this->msg("Store data in the cache (data will expire in 10 seconds)");
$this->msg("Data from the cache:");
echo '<pre>';
var_dump($memcache->get("key"));
echo '</pre>';
} else {
$this->msg("Failed to connect");
}
}
示例15: get
/**
* Pobranie wartości z cache
*
* @param string $module
* @param string $property
* @return mixed
*/
function get($module, $property)
{
$tKey = $this->getKey($module, $property);
if (!isset($this->internalCache[$tKey])) {
$this->internalCache[$tKey] = $this->memcached->get($tKey);
}
return $this->internalCache[$tKey];
}