Esempio n. 1
0
 /**
  * Returns a Cache Item representing the specified key.
  *
  * This method must always return an ItemInterface object, even in case of
  * a cache miss. It MUST NOT return null.
  *
  * @param string $key
  *   The key for which to return the corresponding Cache Item.
  *
  * @return ICacheItem
  *   The corresponding Cache Item.
  * @throws \RuntimeException
  *   If the $key string is not a legal value
  */
 public function getItem($key)
 {
     $item = new CacheItem($key);
     if (isset(self::$cachePool[$this->_pool][$key])) {
         $item->hydrate(self::$cachePool[$this->_pool][$key], true);
     } else {
         $item->hydrate(null, false);
     }
     return $item;
 }
Esempio n. 2
0
 /**
  * Returns a Cache Item representing the specified key.
  *
  * This method must always return an ItemInterface object, even in case of
  * a cache miss. It MUST NOT return null.
  *
  * @param string $key
  *   The key for which to return the corresponding Cache Item.
  *
  * @return ICacheItem
  *   The corresponding Cache Item.
  * @throws \RuntimeException
  *   If the $key string is not a legal value
  */
 public function getItem($key)
 {
     $success = false;
     if (function_exists('apcu_fetch')) {
         $value = apcu_fetch($key, $success);
     } else {
         $value = apc_fetch($key, $success);
     }
     $item = new CacheItem($key);
     $item->hydrate($success ? $value : null, $success);
     return $item;
 }
Esempio n. 3
0
 public function testHydrate()
 {
     $item = new CacheItem('one');
     $item->hydrate('two');
     $this->assertEquals('two', $item->get());
     $this->assertTrue($item->exists());
     $this->assertTrue($item->isHit());
     $item->hydrate(null, false);
     $this->assertEquals(null, $item->get());
     $this->assertFalse($item->exists());
     $this->assertFalse($item->isHit());
 }
Esempio n. 4
0
 /**
  * Returns a Cache Item representing the specified key.
  *
  * This method must always return an ItemInterface object, even in case of
  * a cache miss. It MUST NOT return null.
  *
  * @param string $key
  *   The key for which to return the corresponding Cache Item.
  * @param bool $throw true to throw backend exceptions
  *
  * @return ICacheItem
  *   The corresponding Cache Item.
  * @throws \RuntimeException
  *   If the $key string is not a legal value
  * @throws \Exception
  */
 public function getItem($key, $throw = false)
 {
     $item = new CacheItem($key);
     $item->hydrate(null, false);
     try {
         $value = $this->_connection->get($key);
         if ($value !== false) {
             $item->hydrate($value, true);
         }
     } catch (\Exception $e) {
         if ($throw) {
             throw $e;
         }
     }
     return $item;
 }
Esempio n. 5
0
 /**
  * Delete the DAO from the data store
  *
  * @param IDao $dao
  *
  * @return IDao
  *
  * @throws DataStoreException
  */
 public function delete(IDao $dao)
 {
     $dao = $this->_verifyDao($dao);
     $this->_connectedConnection()->deleteItem(CacheItem::fromDao($dao));
     return $dao;
 }