Exemple #1
0
 /**
  * Set cache
  *
  * @param EntityLoadEvent $event
  *
  * @return void
  */
 public function setCacheForEntity(EntityLoadEvent $event)
 {
     $entity = $event->getEntity();
     if (!$entity->isLoaded()) {
         $this->cache->set($entity);
         $this->dispatcher->dispatch('cache.set', new CacheEvent($entity));
     }
 }
 /**
  * @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));
 }
 /**
  * @param Request  $request
  * @param Response $response
  * @param array    $params
  *
  * @return string
  */
 public function writeCache(Request $request, Response $response, array $params = array())
 {
     $cacheableData = $this->createCacheableData($request, $params, $response->getContent());
     $this->cacheAdapter->set($cacheableData);
     $variantParams = $this->getVariantParams($request);
     $insersectParams = array_intersect_key($params['tags'], array_keys($variantParams));
     $tags = array();
     foreach ($insersectParams as $key => $tag) {
         $tags[$tag] = $variantParams[$tag];
     }
     $this->tagHandler->createTags($tags, $cacheableData->getHashKey());
     return $cacheableData->getHashKey();
 }
Exemple #4
0
 /**
  * @param string $tag
  * @param string $value
  */
 private function registerTag($tag, $value)
 {
     $tagContainerKey = $this->formatTagKey($tag, '');
     $tagKey = $this->formatTagKey($tag, $value);
     $item = $this->createItem($tagContainerKey);
     $keys = unserialize($this->cacheAdapter->get($item));
     if (!is_array($keys)) {
         $keys = array();
     }
     $keys[$tagKey] = $tagKey;
     $item->setDataFromCache(serialize($keys));
     $this->cacheAdapter->set($item);
 }
 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));
 }
Exemple #6
0
 /**
  * Set a value into the cache
  *
  * @param \Itkg\Core\CacheableInterface $item
  *
  * @return void
  */
 public function set(CacheableInterface $item)
 {
     parent::set($item);
     $this->adapter->set($item);
 }