コード例 #1
0
 public function invalidateNode(NodeFormPersistEvent $event)
 {
     $node = $event->getNode();
     try {
         if (isset($node->alias)) {
             $url = $this->requestStack->getMasterRequest()->getSchemeAndHttpHost() . '/' . $node->alias->getAlias();
             $this->cacheManager->invalidatePath($url);
         }
         $this->cacheManager->invalidateRoute('clastic_front_detail', ['id' => $node->getId()]);
     } catch (UnsupportedProxyOperationException $e) {
         // It will expire at some point.
     }
 }
コード例 #2
0
 public function clearCache(HttpCacheEvent $event)
 {
     switch (true) {
         case $event->getSubject() instanceof ContainerInterface:
             $this->cacheManager->invalidateRoute('swp_api_templates_list_containers');
             $this->cacheManager->invalidateRoute('swp_api_templates_get_container', ['id' => $event->getSubject()->getId()]);
             break;
     }
     try {
         $this->cacheManager->flush();
     } catch (ExceptionCollection $e) {
         $this->logger->error($e->getMessage());
     }
 }
コード例 #3
0
ファイル: CacheManagerTest.php プロジェクト: ataxel/tp
    public function testInvalidateRoute()
    {
        $httpCache = \Mockery::mock('\FOS\HttpCache\ProxyClient\Invalidation\PurgeInterface')
            ->shouldReceive('purge')->once()->with('/my/route', array())
            ->shouldReceive('purge')->once()->with('/route/with/params/id/123', array())
            ->shouldReceive('purge')->once()->with('/route/with/params/id/123', array('X-Foo' => 'bar'))
            ->shouldReceive('flush')->once()
            ->getMock();

        $router = \Mockery::mock('\Symfony\Component\Routing\Generator\UrlGeneratorInterface')
            ->shouldReceive('generate')
            ->with('my_route', array())
            ->andReturn('/my/route')

            ->shouldReceive('generate')
            ->with('route_with_params', array('id' => 123))
            ->andReturn('/route/with/params/id/123')
            ->getMock();

        $cacheManager = new CacheManager($httpCache, $router);

        $cacheManager->invalidateRoute('my_route')
            ->invalidateRoute('route_with_params', array('id' => 123))
            ->invalidateRoute('route_with_params', array('id' => 123), array('X-Foo' => 'bar'))
            ->flush();
    }
コード例 #4
0
 /**
  * Invalidate routes from annotations
  *
  * @param array|InvalidateRoute[] $routes
  * @param Request                 $request
  */
 private function invalidateRoutes(array $routes, Request $request)
 {
     $values = $request->attributes->all();
     // if there is an attribute called "request", it needs to be accessed through the request.
     $values['request'] = $request;
     foreach ($routes as $route) {
         $params = array();
         if (null !== $route->getParams()) {
             // Iterate over route params and try to evaluate their values
             foreach ($route->getParams() as $key => $value) {
                 if (is_array($value)) {
                     $value = $this->getExpressionLanguage()->evaluate($value['expression'], $values);
                 }
                 $params[$key] = $value;
             }
         }
         $this->cacheManager->invalidateRoute($route->getName(), $params);
     }
 }