Пример #1
0
 /**
  * @return mixed
  */
 public function getFirstItem()
 {
     $keys = $this->cacheAdapter->get($this->createCacheItem());
     if (!is_array($keys)) {
         return null;
     }
     return array_pop($keys);
 }
Пример #2
0
 /**
  * @param string $key
  */
 public function removeItem($key)
 {
     $values = $this->cacheAdapter->get($this->createCacheItem());
     if (!isset($values[$key])) {
         return;
     }
     unset($values[$key]);
     $this->cacheAdapter->set($this->createCacheItem($values));
 }
Пример #3
0
 /**
  * @param callable $logCallback
  */
 public function processAll(\Closure $logCallback = null)
 {
     while (null !== ($key = $this->reader->getFirstItem())) {
         try {
             $cachedService = $this->cacheAdapter->get($this->createCacheItem($key));
             $this->writer->removeItem($key);
             if ($cachedService instanceof AbstractService) {
                 $service = $this->services->getServiceByIdentifier($cachedService->getIdentifier());
                 $this->cacheWarmer->warm($service, $cachedService);
                 $this->log($logCallback, sprintf('SUCCESS ON REFRESH KEY %s', $key));
             }
         } catch (\Exception $e) {
             $this->log($logCallback, sprintf('ERROR ON REFRESH KEY %s : %s', $key, $e->getMessage()));
         }
     }
 }
Пример #4
0
 public function testCleanByTagsWithIntersectOnlyAndWildcardComparisonAndOneTag()
 {
     $item = new CacheableData('key2', null, 'toto');
     $this->adapter->set($item);
     $item2 = new CacheableData('key3', null, 'toto2');
     $this->adapter->set($item2);
     $this->assertEquals('toto', $this->adapter->get($item));
     $this->manager->addKeyToTag('version', 150, 'key2');
     $this->manager->addKeyToTag('country', 'FR', 'key2');
     $this->manager->addKeyToTag('version', 1500, 'key3');
     $this->manager->addKeyToTag('country', 'FR', 'key3');
     $this->manager->cleanByTags(array('version' => array('value' => 10, 'type' => 'wildcard')), true);
     $this->assertEquals('toto', $this->adapter->get($item));
     $this->assertEquals('toto2', $this->adapter->get($item2));
     $this->manager->cleanByTags(array('version' => array('value' => 150, 'type' => 'wildcard')), true);
     $this->assertFalse($this->adapter->get($item));
     $this->assertFalse($this->adapter->get($item2));
 }
Пример #5
0
 /**
  * @param array $tags
  * @param bool  $withIntersection
  *
  * @return array
  */
 private function getKeysByTags(array $tags, $withIntersection = false)
 {
     $index = 0;
     $keys = array();
     foreach ($tags as $tag) {
         $item = $this->createItem($tag);
         $tagKeys = unserialize($this->cacheAdapter->get($item));
         if (!is_array($tagKeys)) {
             $tagKeys = array();
         }
         if ($withIntersection) {
             if ($index === 0) {
                 $keys = $tagKeys;
             } else {
                 $keys = array_intersect($keys, $tagKeys);
             }
         } else {
             $keys = array_merge($keys, $tagKeys);
         }
         $index++;
     }
     return $keys;
 }
Пример #6
0
 /**
  * Remove cache
  *
  * @return void
  */
 public function removeAll()
 {
     parent::removeAll();
     $this->adapter->removeAll();
 }
Пример #7
0
 /**
  * @param Request  $request
  * @param array    $params
  *
  * @return mixed
  */
 public function readCache(Request $request, array $params = array())
 {
     return $this->cacheAdapter->get($this->createCacheableData($request));
 }
Пример #8
0
 /**
  * Purge all entity cache
  *
  * @return void
  */
 public function purgeCache()
 {
     $this->cache->removeAll();
 }