/**
  * @param array $caches
  * @param \Sonata\PageBundle\Cache\CacheElement $cacheElement
  * @return void
  */
 public function invalidate(array $caches, CacheElement $cacheElement)
 {
     $keys = $cacheElement->getKeys();
     if (!isset($keys['page_id'])) {
         return false;
     }
     foreach ($caches as $cache) {
         if (!$cache instanceof CacheInterface) {
             throw new \RunTimeException('The object must implements the CacheInterface interface');
         }
         try {
             if ($this->logger) {
                 $this->logger->addInfo(sprintf('[%s] flushing cache keys : %s', __CLASS__, json_encode($keys)));
             }
             $cache->flush(array('page_id' => $keys['page_id']));
         } catch (\Exception $e) {
             if ($this->logger) {
                 $this->logger->addAlert(sprintf('[%s] %s', __CLASS__, $e->getMessage()));
             } else {
                 throw new \RunTimeException(null, null, $e);
             }
         }
     }
     return true;
 }
 public function testCache()
 {
     $cacheKeys = array('block_id' => '1');
     $cache = new CacheElement($cacheKeys);
     $this->assertEquals($cacheKeys, $cache->getKeys());
     $this->assertFalse($cache->isExpired());
     $cache = new CacheElement($cacheKeys, -1);
     $this->assertTrue($cache->isExpired());
 }
Example #3
0
 public function getRecord(CacheElement $cacheElement)
 {
     $keys = $cacheElement->getKeys();
     $keys['_timeout'] = array('$gt' => time());
     $results = $this->getCollection()->find($keys);
     if ($results->hasNext()) {
         return $results->getNext();
     }
     return null;
 }
Example #4
0
 protected function getUrl(CacheElement $cacheElement)
 {
     return $this->router->generate('sonata_page_esi_cache', $cacheElement->getKeys(), true);
 }
Example #5
0
 public function computeCacheKeys(CacheElement $cacheElement)
 {
     $keys = $cacheElement->getKeys();
     ksort($keys);
     return md5($this->prefix . serialize($keys));
 }
Example #6
0
 public function getUrl($name, CacheElement $cacheElement)
 {
     $parameters = $cacheElement->getKeys();
     return $this->router->generate($name, $parameters, true);
 }