Version 1
[yaffs-website] / web / core / lib / Drupal / Core / PageCache / ResponsePolicy / DenyNoCacheRoutes.php
1 <?php
2
3 namespace Drupal\Core\PageCache\ResponsePolicy;
4
5 use Drupal\Core\PageCache\ResponsePolicyInterface;
6 use Drupal\Core\Routing\RouteMatchInterface;
7 use Symfony\Component\HttpFoundation\Request;
8 use Symfony\Component\HttpFoundation\Response;
9
10 /**
11  * Cache policy for routes with the 'no_cache' option set.
12  *
13  * This policy rule denies caching of responses generated for routes that have
14  * the 'no_cache' option set to TRUE.
15  */
16 class DenyNoCacheRoutes implements ResponsePolicyInterface {
17
18   /**
19    * The current route match.
20    *
21    * @var \Drupal\Core\Routing\RouteMatchInterface
22    */
23   protected $routeMatch;
24
25   /**
26    * Constructs a deny node preview page cache policy.
27    *
28    * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
29    *   The current route match.
30    */
31   public function __construct(RouteMatchInterface $route_match) {
32     $this->routeMatch = $route_match;
33   }
34
35   /**
36    * {@inheritdoc}
37    */
38   public function check(Response $response, Request $request) {
39     if (($route = $this->routeMatch->getRouteObject()) && $route->getOption('no_cache')) {
40       return static::DENY;
41     }
42   }
43
44 }