You are here

class ExcludePages in Advanced Page Expiration 8

Cache policy that denies caching if the page matches a list of exclusions.

This is in the response policy rather than request policy because a request stack needs to be in place for the RequestPath plugin.

Hierarchy

Expanded class hierarchy of ExcludePages

1 string reference to 'ExcludePages'
ape.services.yml in ./ape.services.yml
ape.services.yml
1 service uses ExcludePages
ape.page_cache_response_policy.exclude_pages in ./ape.services.yml
Drupal\ape\PageCache\ExcludePages

File

src/PageCache/ExcludePages.php, line 17

Namespace

Drupal\ape\PageCache
View source
class ExcludePages implements ResponsePolicyInterface {

  /**
   * A config object for the system performance configuration.
   *
   * @var \Drupal\Core\Config\Config
   */
  protected $config;

  /**
   * Condition plugin manager.
   *
   * @var \Drupal\Component\Plugin\Factory\FactoryInterface $plugin_factory
   *   Factory for condition plugin manager.
   */
  protected $conditionManager;
  public function __construct(ConfigFactoryInterface $config_factory, FactoryInterface $plugin_factory) {
    $this->config = $config_factory
      ->get('ape.settings');
    $this->conditionManager = $plugin_factory;
  }

  /**
   * {@inheritdoc}
   */
  public function check(Response $response, Request $request) {

    /* @var \Drupal\system\Plugin\Condition\RequestPath $condition */
    $condition = $this->conditionManager
      ->createInstance('request_path');
    $condition
      ->setConfig('pages', $this->config
      ->get('exclusions'));
    if (!empty($this->config
      ->get('exclusions')) && $condition
      ->evaluate()) {
      return static::DENY;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExcludePages::$conditionManager protected property Condition plugin manager.
ExcludePages::$config protected property A config object for the system performance configuration.
ExcludePages::check public function Determines whether it is save to store a page in the cache. Overrides ResponsePolicyInterface::check
ExcludePages::__construct public function
ResponsePolicyInterface::DENY constant Deny storage of a page in the cache.