Exemplo n.º 1
0
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  */
 protected function tearDown()
 {
     \Gacela\Gacela::reset();
     if (is_object($this->memcache)) {
         $this->memcache->flush();
     }
 }
 /**
  * Invalidate all the objects in the cache
  * @return void
  */
 public function DeleteAll()
 {
     $this->objMemcache->flush();
     // needs to wait one second after flush.
     //  See comment on http://www.php.net/manual/ru/memcache.flush.php#81420
     sleep(1);
 }
Exemplo n.º 3
0
 function deleteAll()
 {
     if (null === $this->memcache) {
         $this->connect();
     }
     $this->memcache->flush();
 }
Exemplo n.º 4
0
 /**
  * @return PeclMemcache
  **/
 public function clean()
 {
     try {
         $this->instance->flush();
     } catch (BaseException $e) {
         $this->alive = false;
     }
     return parent::clean();
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
0
  * @param $key
  * @return array|bool|string
  */
 public function get($key)
 {
     if (self::$mc == null || empty($key)) {
         return false;
Exemplo n.º 7
0
 protected function setUp()
 {
     parent::setUp();
     if (\extension_loaded('memcache') && @fsockopen('localhost', 11211)) {
         $memcache = new \Memcache();
         $memcache->addServer('localhost');
         $memcache->flush();
         $cacheDriver = new \Doctrine\Common\Cache\MemcacheCache();
         $cacheDriver->setMemcache($memcache);
         $this->_em->getMetadataFactory()->setCacheDriver($cacheDriver);
     } else {
         if (\extension_loaded('apc')) {
             $this->_em->getMetadataFactory()->setCacheDriver(new \Doctrine\Common\Cache\ApcCache());
         } else {
             $this->markTestSkipped('Test only works with a cache enabled.');
         }
     }
     try {
         $this->_schemaTool->createSchema(array($this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC742User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC742Comment')));
     } catch (\Exception $e) {
     }
     // make sure classes will be deserialized from caches
     $this->_em->getMetadataFactory()->setMetadataFor(__NAMESPACE__ . '\\DDC742User', null);
     $this->_em->getMetadataFactory()->setMetadataFor(__NAMESPACE__ . '\\DDC742Comment', null);
 }
Exemplo n.º 8
0
 /**
  * Clears all cache records.
  *
  * @return boolean TRUE if cache is cleared FALSE otherwise
  */
 public function clear()
 {
     if (false === $this->_cache->flush()) {
         return $this->_onError('clear');
     }
     return true;
 }
 public function run($request)
 {
     // Flush memcache
     if (defined('DEVTOOLKIT_USE_MEMCACHED') && DEVTOOLKIT_USE_MEMCACHED) {
         $host = defined('MEMCACHE_HOST') ? MEMCACHE_HOST : 'localhost';
         $port = defined('MEMCACHE_PORT') ? MEMCACHE_PORT : 11211;
         $memcache = new Memcache();
         $connected = $memcache->connect($host, $port);
         if ($connected) {
             echo "Flush memcache<br/>";
             $memcache->flush();
         }
     }
     // Clear file cache
     $folder = TEMP_FOLDER;
     $di = new RecursiveDirectoryIterator($folder, FilesystemIterator::SKIP_DOTS);
     $ri = new RecursiveIteratorIterator($di, RecursiveIteratorIterator::CHILD_FIRST);
     foreach ($ri as $file) {
         echo "Deleting " . $file . '<br/>';
         if ($file->isFile()) {
             unlink($file);
         }
     }
     echo '<hr>Clear completed!';
 }
Exemplo n.º 10
0
 /**
  * Clear/flush all cached data.
  *
  * @return bool
  */
 public function clear()
 {
     if ($this->open()) {
         return $this->memcache->flush();
     }
     return false;
 }
 public function defaultAction()
 {
     $memcache = new Memcache();
     $memcache->flush();
     $usuario = new Usuario();
     $daoUsuario = DAOFactory::getUsuarioDAO();
     /** @var $user User */
     $user = UserService::getCurrentUser();
     if (isset($user)) {
         $usuarioBD = $daoUsuario->queryByGoogle($user->getUserId());
         if (!$usuarioBD) {
             // No existe el usuario
             $usuario->google = $user->getUserId();
             $usuario->correo = $user->getEmail();
             $usuario->nombre = $user->getNickname();
             $daoUsuario->insert($usuario);
         } else {
             $usuario = $usuarioBD;
         }
         $_SESSION['logoutUrl'] = UserService::createLogoutUrl('/index/closeSession');
         $_SESSION['usuario'] = $usuario;
         include 'vod/index.php';
     } else {
         $this->login();
     }
 }
 /**
  * @see Cache::flush()
  */
 public function flush()
 {
     if (!$this->is_connected) {
         return false;
     }
     return $this->memcache->flush();
 }
 /**
  * Flush all existing items in storage.
  *
  * @return  boolean
  *
  * @since   __DEPLOY_VERSION__
  */
 public function flush()
 {
     if (!$this->lockindex()) {
         return false;
     }
     return static::$_db->flush();
 }
Exemplo n.º 14
0
 /**
  * @param int $iTimeToClearInHours = 24
  * 
  * @return bool
  */
 public function GC($iTimeToClearInHours = 24)
 {
     if (0 === $iTimeToClearInHours && $this->oMem) {
         return $this->oMem->flush();
     }
     return false;
 }
Exemplo n.º 15
0
 public function flush()
 {
     if (!isset($this->memcache)) {
         $this->connect();
     }
     return $this->memcache->flush();
 }
Exemplo n.º 16
0
 /**
  * Removes items from the cache by conditions & garbage collector.
  * @param  array  conditions
  * @return void
  */
 public function clean(array $conds)
 {
     if (!empty($conds[Cache::ALL])) {
         $this->memcache->flush();
     } elseif (isset($conds[Cache::TAGS]) || isset($conds[Cache::PRIORITY])) {
         throw new NotSupportedException('Tags and priority is not supported by MemcachedStorage.');
     }
 }
Exemplo n.º 17
0
 /**
  * Delete all cache entries
  *
  * @return  boolean
  */
 public function delete_all()
 {
     $result = $this->_memcache->flush();
     // We must sleep after flushing, or overwriting will not work!
     // @see http://php.net/manual/en/function.memcache-flush.php#81420
     sleep(1);
     return $result;
 }
Exemplo n.º 18
0
 function _remove_all()
 {
     if (!self::$memcache_operational) {
         return;
     }
     debug_add("Calling \\self::\$memcache->flush()");
     $stat = @self::$memcache->flush();
     debug_add("self::\$memcache->flush() returned " . (int) $stat);
 }
Exemplo n.º 19
0
 /**
  * Removes items from the cache by conditions & garbage collector.
  * @param  array  conditions
  * @return void
  */
 public function clean(array $conds)
 {
     if (!empty($conds[Cache::ALL])) {
         $this->memcache->flush();
     } elseif ($this->context) {
         foreach ($this->getJournal()->clean($conds) as $entry) {
             $this->memcache->delete($entry, 0);
         }
     }
 }
Exemplo n.º 20
0
 /**
  * {@inheritdoc}
  *
  * @return \Endeveit\Cache\Interfaces\Driver
  */
 protected static function getDriver()
 {
     if (!class_exists('Memcache')) {
         return null;
     }
     $memcache = new \Memcache();
     $memcache->addServer('127.0.0.1');
     $memcache->flush();
     return new Driver(array('client' => $memcache, 'prefix_id' => 'PHPUnit_'));
 }
Exemplo n.º 21
0
 public function testLoadResourceWithMemcache()
 {
     $memcache = new \Memcache();
     $memcache->addServer('127.0.0.1', 11211);
     $memcache->flush();
     \Gacela\Gacela::instance()->enableCache($memcache);
     $this->assertFalse($memcache->get('test_resource_test'));
     $test = $this->object->loadResource('test');
     $this->assertEquals($test, $memcache->get('test_resource_test'));
 }
Exemplo n.º 22
0
 /**
  * Removes items from the cache by conditions & garbage collector.
  * @param  array  conditions
  * @return void
  */
 public function clean(array $conditions)
 {
     if (!empty($conditions[Cache::ALL])) {
         $this->memcache->flush();
     } elseif ($this->journal) {
         foreach ($this->journal->clean($conditions) as $entry) {
             $this->memcache->delete($entry, 0);
         }
     }
 }
Exemplo n.º 23
0
 /**
  * Записывает массив с данными временного аккаунта
  * @param $newData array('free'=>array('login'=>'test', 'pass'=>'testPass'))
  * @return bool
  */
 public static function configSet($newData)
 {
     $memcache = new \Memcache();
     $memcache->addServer('localhost', 11211);
     $memcache->flush();
     try {
         return $memcache->set($newData, 'Login');
     } catch (\Exception $e) {
         ExpectedException::throwException('2', 'Error write to memcache', '');
     }
 }
Exemplo n.º 24
0
 /**
  * Flush all existing items on Memcache server.
  * Note : only \Hoa\Cache::CLEAN_ALL is supported by Memcache.
  *
  * @param   int  $lifetime    Specific lifetime.
  * @return  void
  * @throws  \Hoa\Cache\Exception
  */
 public function clean($lifetime = Cache::CLEAN_ALL)
 {
     $this->setMemcache();
     if ($lifetime != Cache::CLEAN_ALL) {
         throw new Cache\Exception('Only \\Hoa\\Cache::CLEAN_ALL constant is supported by ' . 'Memcache backend.', 1);
     }
     if (false === @$this->_memcache->flush()) {
         throw new Cache\Exception('Flush all existing items on Memcache server %s failed.', 2, $this->_parameters->getParameter('memcache.database.host'));
     }
     return;
 }
Exemplo n.º 25
0
 public static function setUpBeforeClass()
 {
     if (!extension_loaded('memcache')) {
         static::$cache = null;
         return;
     }
     $memcache = new \Memcache();
     $memcache->connect('unix:///usr/local/var/run/memcached.sock', 0);
     $memcache->flush();
     static::$cache = new \Cachalot\MemcacheCache($memcache, 'cachalot-test:');
 }
Exemplo n.º 26
0
 function clear()
 {
     // $ports = explode(',',MEMCACHED_PORT);
     foreach (explode(',', MEMCACHED_HOST) as $i => $h) {
         $clear_obj = new Memcache();
         $clear_obj->connect($h, '11211') or die('Could not connect');
         $clear_obj->flush();
         unset($clear_obj);
     }
     return true;
 }
Exemplo n.º 27
0
 /**
  * Flush all existing items at the server
  * @param boolean $wait_on_flush Note that after flushing, you have to wait a certain amount of time (in many case < 1s) to be able to write to Memcached again. make if 0/1 to flag to wait on flush or not.
  * @link http://www.php.net/manual/en/memcache.flush.php
  */
 public function flush($wait_on_flush = 1)
 {
     $this->connect();
     $this->mem_cache_instace->flush();
     $this->disconnect();
     self::$_soft_cache = array();
     $this->deinit_internal_cache();
     if ($wait_on_flush) {
         \sleep(1);
     }
 }
Exemplo n.º 28
0
 /**
  * This method is intended only for unit testing. Do NOT use it in other context.
  * Clear all the cache class vars, useful to calculate every value again.
  */
 public function clearValues()
 {
     if (!defined('VB_UNITTEST')) {
         throw new Exception('This method should be called only from unit tests');
     } else {
         $this->memcache_set = true;
         $this->store_result = false;
         $this->memcache->flush();
         parent::clearValues();
     }
 }
Exemplo n.º 29
0
 public function tearDown()
 {
     if (extension_loaded('apc')) {
         \apc_clear_cache();
     }
     if (extension_loaded('memcache')) {
         $memcache = new \Memcache();
         if ($memcache->addServer('localhost', 11211)) {
             $memcache->flush();
         }
     }
 }
Exemplo n.º 30
0
 /**
  * Removes all items from cache
  *
  * @return	bool
  */
 public function delete_all()
 {
     if ($flushed = $this->memcache->flush()) {
         // Memcached has one second granularity, which means it must wait
         // at least 1 sec after flushing, that is, flush() will expire all items
         // set within that second and new items will be invalidated immediately
         sleep(1);
         self::$tags = array();
         $this->store_tags();
     }
     return $flushed;
 }