Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 2
0
	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);
	}
Ejemplo n.º 3
0
 /**
  * @see Cache::_exists()
  */
 protected function _exists($key)
 {
     if (!$this->is_connected) {
         return false;
     }
     return $this->memcache->get($key) !== false;
 }
Ejemplo n.º 4
0
 public function get($key)
 {
     if (null === $this->memcache) {
         $this->connect();
     }
     return $this->memcache->get($key);
 }
Ejemplo n.º 5
0
 /**
  * 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);
 }
Ejemplo n.º 6
0
	/**
	 * 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];
	}
 /**
  * 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);
 }
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 9
0
 /**
  * @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;
 }
Ejemplo n.º 10
0
 /**
  * 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');
 }
Ejemplo n.º 11
0
 public function get($id)
 {
     if (($value = $this->memcache->get($id)) === false) {
         return null;
     }
     return $value;
 }
 public function get($key)
 {
     $status = $this->aerospike->get($this->getKey($key), $record);
     if ($status == \Aerospike::OK) {
         return $record['bins'];
     }
 }
Ejemplo n.º 13
0
 /**
  * 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;
 }
 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");
     }
 }
 /**
  * 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];
 }
Ejemplo n.º 16
0
 /**
  * {@inheritDoc}
  *
  * @return mixed
  */
 public function get($key)
 {
     $data = $this->memcache->get($key);
     if ($data === false) {
         return null;
     }
     return $data;
 }
Ejemplo n.º 17
0
 /**
  * Get cached value
  *
  * @param string $key
  * @param mixed $default
  * @return array|mixed|null|string
  */
 public function get($key, $default = null)
 {
     $key = $this->prepareKey($key);
     if ($data = $this->memcached->get($key)) {
         return $data;
     }
     return $default;
 }
Ejemplo n.º 18
0
 /**
  * {@inheritDoc}
  *
  * @see http://www.php.net/manual/en/memcache.get.php
  */
 protected function _get($key)
 {
     $flags = null;
     // Passed by reference
     $filler = false;
     // Passed by reference, undocumented complaint in PHP7 without
     return $this->_memcache_get_requires_filler ? $this->_connection->get($key, $flags, $filler) : $this->_connection->get($key);
 }
Ejemplo n.º 19
0
 /**
  * Retrieve an item from the cache by key.
  *
  * @param $key
  * @param bool $strict
  * @param null $default
  *
  * @return mixed|null
  *
  * @throws CacheMissException
  */
 public function get($key, $strict = true, $default = null)
 {
     $value = $this->memcache->get($key);
     if (false === $value && $strict) {
         throw new CacheMissException($key);
     }
     return $default;
 }
Ejemplo n.º 20
0
Archivo: Memcache.php Proyecto: n8b/VMN
 /**
  * This function emulates the compare and swap functionality available in the other extension. This allows
  * that functionality to be used when possible and emulated without too much issue, but for obvious reasons
  * this shouldn't be counted on to be exact.
  *
  * @param  string $key
  * @param  mixed  $value
  * @return mixed
  */
 public function cas($key, $value)
 {
     if (($return = @$this->memcached->get($key)) !== false) {
         return $return;
     }
     $this->memcached->set($key, $value);
     return $value;
 }
Ejemplo n.º 21
0
 /**
  * @param string $key
  * @param \DateTime $time
  *
  * @return bool
  */
 public function set($key, \DateTime $time)
 {
     $key = $this->prefix . $key;
     if (!($old_time = $this->memcache->get($key)) || $old_time < $time->getTimestamp()) {
         return $this->memcache->set($key, $time->getTimestamp());
     }
     return true;
 }
Ejemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 public function has($key)
 {
     $data = $this->server->get($this->getKey($key));
     if (!$data) {
         return false;
     }
     return true;
 }
Ejemplo n.º 23
0
 /**
  * {@inheritdoc }
  */
 public function has($key)
 {
     $tKey = $this->getKey($key);
     if ($this->server->get($tKey)) {
         return true;
     }
     return false;
 }
 /**
  * {@inheritdoc}
  */
 public function isExists()
 {
     if (false !== $this->memcacheInstance->get($this->keyName)) {
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 25
0
 /**
  * 从session中读取数据
  *
  * @param    string $sessionId session的ID
  *
  * @return    mixed    返回session中对应的数据
  */
 public function read($sessionId)
 {
     $out = $this->handler->get($this->storageKey($sessionId));
     if ($out === false || $out == null) {
         return '';
     } else {
         return $out;
     }
 }
Ejemplo n.º 26
0
 /**
  * Verifica si la llave existe.
  *
  * @param string $llave
  *
  * @return bool
  */
 public function existe($llave)
 {
     $temp = $this->gestor->get(array($llave));
     if (isset($temp)) {
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 27
0
 public function get($id)
 {
     $flags = null;
     $result = @$this->memcache->get($id, $flags);
     if (false === $result && (is_null($flags) || 1 !== $flags >> 16)) {
         return null;
     }
     return $result;
 }
Ejemplo n.º 28
0
 /**
  * Retrieve an item from the cache.
  *
  * @param string $name The name of the cache
  * @param boolean $hard_refresh True if we should do a hard refresh
  * @return mixed Cache data if successful, false if failure
  */
 function fetch($name, $hard_refresh = false)
 {
     $data = $this->memcache->get($this->unique_id . "_" . $name);
     if ($data === false) {
         return false;
     } else {
         return $data;
     }
 }
Ejemplo n.º 29
0
 public function testIncrementCacheWithDelete()
 {
     $key = 'test_test_mapper_customer_version';
     $this->assertFalse($this->memcache->get($key));
     $this->object->findAll();
     $this->assertSame(0, $this->memcache->get($key));
     $this->object->delete(array('id' => 2));
     $this->assertSame(1, $this->memcache->get($key));
 }
Ejemplo n.º 30
0
 /**
  * Retrieve an item from the cache by key.
  *
  * @param string $key
  *
  * @return mixed
  */
 public function get($key)
 {
     $value = $this->memcache->get($this->prefix . $key);
     if (sizeof($value) > 0 && $value !== false) {
         return $value;
     } else {
         return;
     }
     return $value;
 }