예제 #1
1
 public function tsli_save_post($post_ID, $post, $update)
 {
     $memcache = new Memcached();
     $memcache->addServer('127.0.0.1', 11211);
     foreach ($post as $key => $value) {
         $memcache->delete(md5(json_encode(array("field" => $key, "id" => $post_ID, "type" => "tsli"))));
         $memcache->delete(md5(json_encode(array("field" => $key, "slug" => $post->post_name, "type" => "tsli"))));
     }
     $memcache->delete(md5(json_encode(array("type" => "tsli", "slug" => $post->post_name))));
     $memcache->delete(md5(json_encode(array("type" => "tsli", "id" => $post_ID))));
 }
예제 #2
0
 /**
  * Delete an item from the cache
  *
  * @param string $key cache key
  */
 public function Delete($key)
 {
     if (empty($key)) {
         return;
     }
     $this->memcache->delete($key);
 }
예제 #3
0
 /**
  * @param string $name
  */
 public function invalidate($name)
 {
     if (!$this->memcached instanceof \Memcached) {
         $this->connect();
     }
     $this->memcached->delete($name);
 }
예제 #4
0
 /**
  * 解锁
  * @param unknown $key
  */
 public function release($key)
 {
     $key = $this->prefix . $key;
     if ($this->memcached->get($key) === $this->Identifier) {
         $this->memcached->delete($key);
     }
 }
예제 #5
0
 /**
  * Release lock
  *
  * @param string $name name of lock
  * @return bool
  */
 public function releaseLock($name)
 {
     if (isset($this->keys[$name]) && $this->memcache->delete($name)) {
         unset($this->keys[$name]);
         return true;
     }
     return false;
 }
예제 #6
0
 function delete($key)
 {
     $key = str_replace('\\', '/', $key);
     if (!$this->memcached->delete($key)) {
         $message = sprintf('Memcache::delete() with key "%s" failed', $key);
         \ManiaLib\Utils\Logger::error($message);
     }
 }
예제 #7
0
 public function getCounter()
 {
     $memcached = new \Memcached();
     $memcached->addServer($GLOBALS['settings']['memcached']['host'], $GLOBALS['settings']['memcached']['port']);
     $memcached->delete('prefix/counter/value');
     $memcached->delete('prefix/counter/value2');
     return new \Cachet\Counter\Memcache($memcached, 'prefix');
 }
 public function testLoadStatusEmpty()
 {
     $this->_connection->delete('EjsmontCircuitBreakerAAAbbb');
     $this->assertEquals("", $this->_adapter->loadStatus('GGG', ''));
     $this->assertEquals("", $this->_adapter->loadStatus('AAA', 'bbb'));
     $this->_adapter->saveStatus('B', 'bbb', "");
     $this->assertEquals("", $this->_adapter->loadStatus('A', 'bbb'), 6);
     $this->assertEquals("", $this->_adapter->loadStatus('B', 'bbb'), 7);
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 protected function deleteArrayDataFromStorage(array $keys)
 {
     $deleted = true;
     foreach ($keys as $key) {
         if ($this->memcached->delete($key) === false) {
             $deleted = false;
         }
     }
     return $deleted;
 }
예제 #10
0
 public function delete($key)
 {
     $this->memcachedObj->delete($key);
     $resultCode = $this->memcachedObj->getResultCode();
     if ($resultCode != \Memcached::RES_SUCCESS && $resultCode != \Memcached::RES_NOTFOUND) {
         throw new StorageException('[STORAGE] "' . $this->getStorageName() . '::delete" failed for key "' . $key . '"!' . ' StorageRespCode: ' . $resultCode);
     }
     unset($this->casArray[$key]);
     return $resultCode;
 }
 /**
  * {@inheritdoc}
  */
 protected function doDelete($key, array $options = array())
 {
     $this->client->delete($this->getKey($key, $options));
     switch (true) {
         case $this->isSuccess():
             return new CacheResponse(true, true, true);
         case $this->isNotFound():
             return new CacheResponse(false, false, true, CacheResponse::RESOURCE_NOT_FOUND);
     }
     /* If everything failed we're dealing with a backend (connection) error. */
     return new CacheResponse(false, false, false, CacheResponse::CONNECTION_ERROR);
 }
예제 #12
0
 /**
  * 批量设置键值(当键名不存在时);<br>
  * 只有当键值全部设置成功时,才返回true,否则返回false并尝试回滚
  * @param array $sets   键值数组
  * @return boolean      是否成功
  */
 public function mSetNX($sets)
 {
     try {
         $keys = [];
         $status = true;
         foreach ($sets as $key => $value) {
             $status = $this->handler->add($key, self::setValue($value));
             if ($status) {
                 $keys[] = $key;
             } else {
                 break;
             }
         }
         //如果失败,尝试回滚,但不保证成功
         if (!$status) {
             foreach ($keys as $key) {
                 $this->handler->delete($key);
             }
         }
         return $status;
     } catch (Exception $ex) {
         self::exception($ex);
         //连接状态置为false
         $this->isConnected = false;
     }
     return false;
 }
예제 #13
0
 /**
  * Remove a cache record directly. This method is implemented by the cache
  * drivers and used in Doctrine_Cache_Driver::delete()
  *
  * @param string $id cache id
  * @return boolean true if no problem
  */
 protected function _doDelete($id)
 {
     if (false == $this->_memcached->getOption(Memcached::OPT_BINARY_PROTOCOL)) {
         $id = str_replace(' ', '_', $id);
     }
     return $this->_memcached->delete($id);
 }
예제 #14
0
파일: Approve.php 프로젝트: 4otaku/api
 public function process()
 {
     $id = $this->get('id');
     $state = (string) $this->get('state');
     if (!$this->is_moderator()) {
         throw new ErrorApi(ErrorApi::INSUFFICIENT_RIGHTS);
     }
     if (empty($id) || empty($state)) {
         throw new ErrorApi(ErrorApi::MISSING_INPUT);
     }
     $state = Meta::parse($state);
     if (empty($state)) {
         throw new ErrorApi(ErrorApi::INCORRECT_INPUT);
     }
     $this->db->update('art', array('sortdate' => $this->db->unix_to_date()), $id);
     $this->remove_meta(Meta::ART, $id, Meta::STATE, Meta::STATE_APPROVED);
     $this->remove_meta(Meta::ART, $id, Meta::STATE, Meta::STATE_UNAPPROVED);
     $this->remove_meta(Meta::ART, $id, Meta::STATE, Meta::STATE_DISAPPROVED);
     $this->remove_meta(Meta::ART, $id, Meta::STATE, Meta::STATE_DELETED);
     $this->add_meta(Meta::ART, $id, Meta::STATE, $state);
     $cache = new \Memcached("access_checker");
     $cache->addServer("localhost", 11211);
     $cache->delete('is_pic_safe_' . $this->db->get_field('art', 'md5', $id));
     $this->set_success(true);
 }
예제 #15
0
파일: Cache.php 프로젝트: sebst3r/nZEDb
 /**
  * Delete data tied to a key on the cache server.
  *
  * @param string $key Key we can use to retrieve the data.
  *
  * @return bool True if deleted, false if not.
  * @access public
  */
 public function delete($key)
 {
     if ($this->connected === true && $this->ping() === true) {
         return (bool) $this->server->delete($key);
     }
     return false;
 }
예제 #16
0
 /**
  * delete
  *
  * @param mixed $identifier identifier to delete the entry for
  *
  * @return boolean
  */
 public function delete($identifier = null)
 {
     if (!$identifier) {
         throw new \InvalidArgumentException('identifier is a required argument');
     }
     return $this->memcached->delete($this->fileName($identifier));
 }
예제 #17
0
 /**
  * destroy of the session
  *
  * @param string $sessionId
  * @return bool
  * 
  */
 function destroy($sessionId)
 {
     $this->memcache->delete($sessionId);
     $this->memcache->delete('db-' . $sessionId);
     sql_remove_sess_by_id($sessionId);
     return true;
 }
 public function test_MemcachedLock_Exceptions()
 {
     $key = static::TEST_KEY;
     $MemcachedLock = new MemcachedLock(static::$Memcached, $key, MemcachedLock::FLAG_USE_SELF_EXPIRE_SYNC);
     $this->assertSame(true, $MemcachedLock->acquire(2));
     $this->assertSame(true, $MemcachedLock->isLocked());
     static::$Memcached->delete($key);
     try {
         $MemcachedLock->release();
         $this->assertFalse('Expect LostLockException');
     } catch (\Exception $Ex) {
         $this->assertInstanceOf(LostLockException::class, $Ex);
     }
     $this->assertSame(false, $MemcachedLock->isLocked());
     $this->assertSame(true, $MemcachedLock->acquire(2));
     $this->assertSame(true, $MemcachedLock->isLocked());
     static::$Memcached->delete($key);
     $this->assertSame(false, $MemcachedLock->isExists());
     try {
         $MemcachedLock->isLocked();
         $this->assertFalse('Expect LostLockException');
     } catch (\Exception $Ex) {
         $this->assertInstanceOf(LostLockException::class, $Ex);
     }
 }
예제 #19
0
 protected function _delete(VO $vo)
 {
     if (!$this->memcached) {
         return true;
     }
     return $this->memcached->delete($this->getMemcachedCompleteKey($vo->getId()));
 }
예제 #20
0
 /**
  * Remove an item.
  *
  * Options:
  *  - namespace <string> optional
  *    - The namespace to use (Default: namespace of object)
  *  - ignore_missing_items <boolean> optional
  *    - Throw exception on missing item or return false
  *
  * @param  string $key
  * @param  array $options
  * @return boolean
  * @throws Exception
  *
  * @triggers removeItem.pre(PreEvent)
  * @triggers removeItem.post(PostEvent)
  * @triggers removeItem.exception(ExceptionEvent)
  */
 public function removeItem($key, array $options = array())
 {
     $baseOptions = $this->getOptions();
     if (!$baseOptions->getWritable()) {
         return false;
     }
     $this->normalizeOptions($options);
     $this->normalizeKey($key);
     $args = new ArrayObject(array('key' => &$key, 'value' => &$value, 'options' => &$options));
     try {
         $eventRs = $this->triggerPre(__FUNCTION__, $args);
         if ($eventRs->stopped()) {
             return $eventRs->last();
         }
         $internalKey = $options['namespace'] . $baseOptions->getNamespaceSeparator() . $key;
         $result = $this->memcached->delete($internalKey);
         if ($result === false) {
             if (!$options['ignore_missing_items']) {
                 throw new Exception\ItemNotFoundException("Key '{$internalKey}' not found");
             }
         }
         $result = true;
         return $this->triggerPost(__FUNCTION__, $args, $result);
     } catch (\Exception $e) {
         return $this->triggerException(__FUNCTION__, $args, $e);
     }
 }
예제 #21
0
 /**
  * @see Cache::_delete()
  */
 protected function _delete($key)
 {
     if (!$this->is_connected) {
         return false;
     }
     return $this->memcached->delete($key);
 }
예제 #22
0
 /**
  * Delete an entry
  * @param string $key
  */
 public function delete($key)
 {
     if ($this->enabled === false) {
         return;
     }
     $this->memcached->delete($key);
 }
 /**
  * Delete data from cache
  *
  * @param array $keys array of keys to delete
  * @return boolean true on success
  */
 protected function delete(array $keys)
 {
     foreach ($keys as $key) {
         $this->memcacheObj->delete(sha1($key));
     }
     return true;
 }
예제 #24
0
 public function clear($prefix = '')
 {
     $prefix = $this->getNamespace() . $prefix;
     $allKeys = self::$cache->getAllKeys();
     if ($allKeys === false) {
         // newer Memcached doesn't like getAllKeys(), flush everything
         self::$cache->flush();
         return true;
     }
     $keys = array();
     $prefixLength = strlen($prefix);
     foreach ($allKeys as $key) {
         if (substr($key, 0, $prefixLength) === $prefix) {
             $keys[] = $key;
         }
     }
     if (method_exists(self::$cache, 'deleteMulti')) {
         self::$cache->deleteMulti($keys);
     } else {
         foreach ($keys as $key) {
             self::$cache->delete($key);
         }
     }
     return true;
 }
예제 #25
0
 /**
  * {@inheritdoc}
  */
 public function flush() : StorageInterface
 {
     if ($keys = $this->memcached->get($this->prefix)) {
         $this->memcached->delete($this->prefix);
         $this->memcached->deleteMulti(explode('|', $keys));
     }
     return $this;
 }
예제 #26
0
 /**
  * Deletes a value from the cache by its key
  *
  * @param int|string $keyName
  * @return boolean
  */
 public function delete($keyName)
 {
     if ($keyName === null) {
         $keyName = $this->_lastKey;
     }
     $keyName = $this->_addPrefix($keyName);
     $this->_backend->delete($keyName);
 }
예제 #27
0
파일: callback.php 프로젝트: badlamer/hhvm
 function __construct()
 {
     $memc = new Memcached();
     $memc->addServer('localhost', '11211');
     $memc->delete('callback_test');
     var_dump($memc->get('callback_test', array($this, 'ReadThrough')));
     var_dump($memc->get('callback_test'));
 }
예제 #28
0
 /**
  * Remove values from cache
  *
  * @param  array $keys list of keys to delete
  *
  * @return boolean true on success, false on failure
  */
 protected function delete(array $keys)
 {
     foreach ($keys as $k) {
         $k = sha1($k);
         $this->memcached->delete($k);
     }
     return true;
 }
예제 #29
-1
 /**
  * Destroy a session.
  * Expects a session id.
  * @param string $sessionId
  * @return boolean
  */
 public function destroy($sessionId = '')
 {
     if ($sessionId !== '') {
         $this->_memcached->delete($this->_key($sessionId));
     }
     return true;
 }
예제 #30
-2
 public function delete($key)
 {
     $key = $this->prefix . $key;
     $this->store->delete($key);
     $this->removeFromIndex($key);
     return $this;
 }