Ejemplo n.º 1
0
 /**
  * Store data on the cache server.
  *
  * @param string       $key        Key we can use to retrieve the data.
  * @param string|array $data       Data to store on the cache server.
  * @param int          $expiration Time before the data expires on the cache server.
  *
  * @return bool Success/Failure.
  * @access public
  */
 public function set($key, $data, $expiration)
 {
     if ($this->connected === true && $this->ping() === true) {
         return $this->server->set($key, $this->isRedis ? $this->IgBinarySupport ? igbinary_serialize($data) : serialize($data) : $data, $expiration);
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function set($key, $value, $ttl = null)
 {
     if (!$ttl) {
         $ttl = $this->ttl;
     }
     $this->server->set($this->getKey($key), $this->pack($value), time() + $ttl);
 }
Ejemplo n.º 3
0
 /**
  * save
  *
  * @param mixed  $identifier identifier to save
  * @param string $amount     the current amount
  * @param string $timespan   the timespan in seconds
  *
  * @return boolean
  */
 public function save($identifier = null, $amount = null, $timespan = null)
 {
     if (!$identifier && !$amount && !$timespan) {
         throw new \InvalidArgumentException('identifier, amount and timespan are required');
     }
     return $this->memcached->set($this->fileName($identifier), $amount, $timespan);
 }
Ejemplo n.º 4
0
 /**
  * @see Cache::_set()
  */
 protected function _set($key, $value, $ttl = 0)
 {
     if (!$this->is_connected) {
         return false;
     }
     return $this->memcached->set($key, $value, $ttl);
 }
Ejemplo n.º 5
0
 /**
  * @param string $key
  * @param mixed $var
  * @param int $expiration
  * @return bool True on success, false on failure
  */
 public function set($key, $var, $expiration = null)
 {
     if (!$this->memcached) {
         throw new CacheException('No memcached defined.');
     }
     return $this->memcached->set($key, $var, $expiration === null ? 0 : $expiration);
 }
Ejemplo n.º 6
0
 /**
  * Set a value against a key in the cache.
  *
  * @param string $key     The key to store against
  * @param string $value   A json_encoded value
  * @param int    $expires Optional expiry time in seconds from now
  */
 public function set($key, $value = null, $expires = 0)
 {
     if ($value === null) {
         return $this->clear($key);
     }
     return $this->client->set($key, $value, $expires);
 }
Ejemplo n.º 7
0
 /**
  * @param $key
  * @param $data
  * @return bool
  */
 public function set($key, $data)
 {
     if (!is_null($this->memcache)) {
         $this->memcache->set($key, $data, $this->expire);
     }
     return false;
 }
Ejemplo n.º 8
0
 /**
  * Set a value in the cache
  *
  * @param string $p_sKey The Key
  * @param mixed $p_mData The Data
  * @param integer $p_mTTL The Time To Live
  * @return boolean
  */
 function set($p_sKey, $p_mData, $p_mTTL = 0)
 {
     if ($this->_serverAdded === false) {
         $this->addServer('localhost');
     }
     return $this->_handler->set($p_sKey, $p_mData, is_numeric($p_mTTL) ? $p_mTTL : strtotime($p_mTTL));
 }
Ejemplo n.º 9
0
 /**
  * set cache-item by key => value + ttl
  *
  * @param string $key
  * @param mixed  $value
  * @param int    $ttl
  *
  * @return boolean
  */
 public function setExpired($key, $value, $ttl)
 {
     if ($ttl > 2592000) {
         $ttl = 2592000;
     }
     return $this->memcached->set($key, $value, $ttl);
 }
Ejemplo n.º 10
0
 /**
  * @inheritdoc
  */
 public function put($key, $value, $ttl = 0)
 {
     if ($ttl > 30 * 24 * 3600) {
         $ttl = time() + $ttl;
     }
     return $this->memcached->set($key, $value, 0, (int) $ttl);
 }
Ejemplo n.º 11
0
 /**
  * Store an item in the cache for a given number of minutes.
  *
  * @param  string $key
  * @param  mixed $value
  * @param  int $seconds
  * @param  bool $strict
  *
  * @throws CacheSetException
  *
  * @return bool
  */
 public function set($key, $value, $seconds, $strict = true)
 {
     $set = $this->memcached->set($key, $value, $seconds);
     if (!$set && $strict) {
         throw new CacheSetException($key);
     }
 }
Ejemplo n.º 12
0
 /**
  * Sets an item into the cache
  *
  * @param string $key cache key
  * @param mixed $value object to cache
  * @param int $lifetime cached object lifetime
  */
 public function Set($key, $value, $lifetime)
 {
     if (empty($key) || empty($value)) {
         return;
     }
     $this->memcache->set($key, $value, false, time() + $lifetime);
 }
Ejemplo n.º 13
0
 public function set($id, $value, $ttl = null)
 {
     $ttl = $ttl ?: 0;
     if ($ttl > 0) {
         $ttl = time() + $ttl;
     }
     return $this->memcached->set($id, $value, $ttl);
 }
Ejemplo n.º 14
0
 public function set($key, $value, $ttl = 0)
 {
     if ($ttl > 0) {
         return self::$cache->set($this->getNamespace() . $key, $value, $ttl);
     } else {
         return self::$cache->set($this->getNamespace() . $key, $value);
     }
 }
Ejemplo n.º 15
0
 public function setUp()
 {
     self::$memcached->flush();
     self::$memcached->quit();
     self::$memcached->set('found', array('count' => 5, 'time' => strtotime('2015-01-01 00:00:00')));
     self::$memcached->set('oldkey', 'old story');
     $this->storage = new MemcachedStorage(self::$memcached);
 }
 /**
  * Stores data in the cache.
  * 
  * @param string $key The key under which to save the data.
  * @param mixed $data Any object or value that can be serialized.
  * @param int $duration How long to cache the data in seconds, or 0 for indefinite.
  * @return boolean Indicates whether the value was cached successfully.
  */
 public function save($key, $data, $duration)
 {
     if (isset($this->cache)) {
         $hashedKey = hash("sha1", MEMCACHED_PREFIX . $key);
         return $this->cache->set($hashedKey, $data, $duration);
     }
     return true;
 }
Ejemplo n.º 17
0
 /**
  * {@inheritdoc}
  */
 public function write($key, $data, $expires = 60, $compressed = false)
 {
     $cmp = $this->driver->getOption(Memcached::OPT_COMPRESSION);
     $this->driver->setOption(Memcached::OPT_COMPRESSION, $compressed);
     $cached = $this->driver->set($key, $data, $expires);
     $this->driver->setOption(Memcached::OPT_COMPRESSION, $cmp);
     return $cached;
 }
Ejemplo n.º 18
0
 /**
  * Store a Gameserver object in the cache
  *
  * @param \SQ\Gameserver $server
  */
 public function put(Gameserver $server)
 {
     if ($this->memcached != null) {
         $this->memcached->set(self::getKey($server), $server->toJSON());
     } else {
         file_put_contents(self::getFileName($server), $server->toJSON());
     }
 }
Ejemplo n.º 19
0
 /**
  * Save values for a set of keys to cache
  *
  * @param  array $keys list of values to save
  * @param  int   $expire expiration time
  *
  * @return boolean true on success, false on failure
  */
 protected function write(array $keys, $expire = null)
 {
     foreach ($keys as $k => $v) {
         $k = sha1($k);
         $this->memcached->set($k, $v, $expire);
     }
     return true;
 }
Ejemplo n.º 20
0
 public function cas($key, $value)
 {
     if (($return = @$this->memcached->get($key)) !== false) {
         return $return;
     }
     $this->memcached->set($key, $value);
     return $value;
 }
 /**
  * Save item in the cache.
  * 
  * @param string $key
  * @param string $value
  * @param int $ttl
  * @return void
  * 
  * @throws Ejsmont\CircuitBreaker\Storage\StorageException if storage error occurs, handler can not be used
  */
 protected function save($key, $value, $ttl)
 {
     try {
         $this->memcached->set($key, $value, $ttl);
     } catch (\Exception $e) {
         throw new StorageException("Failed to save memcached key: {$key}", 1, $e);
     }
 }
Ejemplo n.º 22
0
 /**
  * Write an item to the cache for a given number of minutes.
  *
  * <code>
  *		// Put an item in the cache for 15 minutes
  *		Cache::put('name', 'Taylor', 15);
  * </code>
  *
  * @param  string  $key
  * @param  mixed   $value
  * @param  int     $minutes
  * @return void
  */
 public function put($key, $value, $minutes)
 {
     if ($this->sectionable($key)) {
         list($section, $key) = $this->parse($key);
         return $this->put_in_section($section, $key, $value, $minutes);
     } else {
         $this->memcache->set($this->key . $key, $value, $minutes * 60);
     }
 }
Ejemplo n.º 23
0
 public function createRate($key, $limit, $period)
 {
     $info = array();
     $info['limit'] = $limit;
     $info['calls'] = 1;
     $info['reset'] = time() + $period;
     $this->client->set($key, $info, $period);
     return $this->getRateInfo($key);
 }
Ejemplo n.º 24
0
 /**
  * Save value
  * @param  string
  * @param  string
  * @throws RunTimeException
  */
 public function store($key, $val)
 {
     $val = gzcompress(json_encode($val));
     if ($this->Memcached->set($this->table . '_' . $key, $val, 600) === false) {
         $msg = $this->Memcached->getResultMessage();
         $code = $this->Memcached->getResultCode();
         throw new \RunTimeException("Memcached Error (store): " . $msg . "(" . $code . ")");
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function doSet($key, $value, $expiration, array $options = array())
 {
     $this->client->set($this->getKey($key, $options), $value, $expiration);
     /* Success should never fail, so anything other than success is also a server (connection) error. */
     if ($this->isSuccess()) {
         return new CacheResponse(true, true, true);
     }
     return new CacheResponse(false, false, false, CacheResponse::CONNECTION_ERROR);
 }
Ejemplo n.º 26
0
 protected final function setCache($data)
 {
     list($name, $key) = $this->configCache();
     if (self::$memcache) {
         self::$memcache->set($name . ':' . $data->{$key}, $data, self::$memcache_expire);
     } else {
         self::$cache[$name][$data->{$key}] = $data;
     }
 }
Ejemplo n.º 27
0
 /**
  * {@inheritdoc}
  */
 public function add(string $alias, FeatureInterface $feature) : StorageInterface
 {
     $key = $this->key($alias);
     $this->memcached->set($key, $this->feature($feature));
     if (!$this->memcached->append($this->prefix, "|{$key}")) {
         $this->memcached->set($this->prefix, $key);
     }
     return $this;
 }
Ejemplo n.º 28
0
 /**
  * @param string $name
  * @param string $value
  * @param integer $lifeTime
  * @throws \InvalidArgumentException
  */
 public function write($name, $value, $lifeTime)
 {
     if (!is_int($lifeTime) || $lifeTime < 0) {
         throw new \InvalidArgumentException('Lifetime must be integer greater than or equal to 0. Get "' . $lifeTime . '"');
     }
     if (!$this->memcached instanceof \Memcached) {
         $this->connect();
     }
     $this->memcached->set($name, $value, $lifeTime);
 }
Ejemplo n.º 29
0
 public function setUp()
 {
     parent::setUp();
     $this->memcache = new \Memcached();
     $this->memcache->addServer(self::TEST_MEMCACHE_SERVER, self::TEST_MEMCACHE_PORT);
     $this->memcache->flush();
     if (!$this->memcache->set('test', 1, time() + 100)) {
         throw new \RuntimeException('Cannot save item to memcache. ' . $this->memcache->getResultMessage());
     }
 }
Ejemplo n.º 30
0
 public function set($key, $value, $ttl = 0)
 {
     if ($ttl > 0) {
         $result = self::$cache->set($this->getNamespace() . $key, $value, $ttl);
     } else {
         $result = self::$cache->set($this->getNamespace() . $key, $value);
     }
     $this->verifyReturnCode();
     return $result;
 }