You are here

class PageCacheResponsePolicy in Media Download 1.2.x

Same name and namespace in other branches
  1. 1.0.x src/PageCacheResponsePolicy.php \Drupal\media_download\PageCacheResponsePolicy
  2. 1.1.x src/PageCacheResponsePolicy.php \Drupal\media_download\PageCacheResponsePolicy

Deny caching of BinaryFileResponse and StreamedResponse class hierarchies.

Copyright (C) 2021 Library Solutions, LLC (et al.).

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

Hierarchy

Expanded class hierarchy of PageCacheResponsePolicy

1 string reference to 'PageCacheResponsePolicy'
media_download.services.yml in ./media_download.services.yml
media_download.services.yml
1 service uses PageCacheResponsePolicy
media_download.page_cache_response_policy in ./media_download.services.yml
Drupal\media_download\PageCacheResponsePolicy

File

src/PageCacheResponsePolicy.php, line 22

Namespace

Drupal\media_download
View source
class PageCacheResponsePolicy implements ResponsePolicyInterface {

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

    // Currently it is not possible to cache binary file or streamed responses.
    // @see https://github.com/symfony/symfony/issues/9128#issuecomment-25088678
    if ($response instanceof BinaryFileResponse || $response instanceof StreamedResponse) {
      return static::DENY;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PageCacheResponsePolicy::check public function Determines whether it is save to store a page in the cache. Overrides ResponsePolicyInterface::check
ResponsePolicyInterface::DENY constant Deny storage of a page in the cache.