You are here

class DenyNoCacheRoutes in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/PageCache/ResponsePolicy/DenyNoCacheRoutes.php \Drupal\Core\PageCache\ResponsePolicy\DenyNoCacheRoutes
  2. 9 core/lib/Drupal/Core/PageCache/ResponsePolicy/DenyNoCacheRoutes.php \Drupal\Core\PageCache\ResponsePolicy\DenyNoCacheRoutes

Cache policy for routes with the 'no_cache' option set.

This policy rule denies caching of responses generated for routes that have the 'no_cache' option set to TRUE.

Hierarchy

Expanded class hierarchy of DenyNoCacheRoutes

1 string reference to 'DenyNoCacheRoutes'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses DenyNoCacheRoutes
page_cache_no_cache_routes in core/core.services.yml
Drupal\Core\PageCache\ResponsePolicy\DenyNoCacheRoutes

File

core/lib/Drupal/Core/PageCache/ResponsePolicy/DenyNoCacheRoutes.php, line 16

Namespace

Drupal\Core\PageCache\ResponsePolicy
View source
class DenyNoCacheRoutes implements ResponsePolicyInterface {

  /**
   * The current route match.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * Constructs a deny node preview page cache policy.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The current route match.
   */
  public function __construct(RouteMatchInterface $route_match) {
    $this->routeMatch = $route_match;
  }

  /**
   * {@inheritdoc}
   */
  public function check(Response $response, Request $request) {
    if (($route = $this->routeMatch
      ->getRouteObject()) && $route
      ->getOption('no_cache')) {
      return static::DENY;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DenyNoCacheRoutes::$routeMatch protected property The current route match.
DenyNoCacheRoutes::check public function Determines whether it is save to store a page in the cache. Overrides ResponsePolicyInterface::check
DenyNoCacheRoutes::__construct public function Constructs a deny node preview page cache policy.
ResponsePolicyInterface::DENY constant Deny storage of a page in the cache.