Update to drupal-org-drupal 8.0.0-rc2. For more information, see https://www.drupal.org/node/2598668
This commit is contained in:
parent
f32e58e4b1
commit
8e18df8c36
3062 changed files with 15044 additions and 172506 deletions
|
@ -7,12 +7,11 @@
|
|||
|
||||
namespace Drupal\page_cache\StackMiddleware;
|
||||
|
||||
use Drupal\Component\Utility\UserAgent;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheableResponseInterface;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\PageCache\RequestPolicyInterface;
|
||||
use Drupal\Core\PageCache\ResponsePolicyInterface;
|
||||
use Drupal\Core\Site\Settings;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -208,25 +207,55 @@ class PageCache implements HttpKernelInterface {
|
|||
* A response object.
|
||||
*/
|
||||
protected function fetch(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
|
||||
/** @var \Symfony\Component\HttpFoundation\Response $response */
|
||||
$response = $this->httpKernel->handle($request, $type, $catch);
|
||||
|
||||
// Currently it is not possible to cache some types of responses. Therefore
|
||||
// exclude binary file responses (generated files, e.g. images with image
|
||||
// styles) and streamed responses (files directly read from the disk).
|
||||
// see: https://github.com/symfony/symfony/issues/9128#issuecomment-25088678
|
||||
// Drupal's primary cache invalidation architecture is cache tags: any
|
||||
// response that varies by a configuration value or data in a content
|
||||
// entity should have cache tags, to allow for instant cache invalidation
|
||||
// when that data is updated. However, HTTP does not standardize how to
|
||||
// encode cache tags in a response. Different CDNs implement their own
|
||||
// approaches, and configurable reverse proxies (e.g., Varnish) allow for
|
||||
// custom implementations. To keep Drupal's internal page cache simple, we
|
||||
// only cache CacheableResponseInterface responses, since those provide a
|
||||
// defined API for retrieving cache tags. For responses that do not
|
||||
// implement CacheableResponseInterface, there's no easy way to distinguish
|
||||
// responses that truly don't depend on any site data from responses that
|
||||
// contain invalidation information customized to a particular proxy or
|
||||
// CDN.
|
||||
// - Drupal modules are encouraged to use CacheableResponseInterface
|
||||
// responses where possible and to leave the encoding of that information
|
||||
// into response headers to the corresponding proxy/CDN integration
|
||||
// modules.
|
||||
// - Custom applications that wish to provide internal page cache support
|
||||
// for responses that do not implement CacheableResponseInterface may do
|
||||
// so by replacing/extending this middleware service or adding another
|
||||
// one.
|
||||
if (!$response instanceof CacheableResponseInterface) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Currently it is not possible to cache binary file or streamed responses:
|
||||
// https://github.com/symfony/symfony/issues/9128#issuecomment-25088678.
|
||||
// Therefore exclude them, even for subclasses that implement
|
||||
// CacheableResponseInterface.
|
||||
if ($response instanceof BinaryFileResponse || $response instanceof StreamedResponse) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Allow policy rules to further restrict which responses to cache.
|
||||
if ($this->responsePolicy->check($response, $request) === ResponsePolicyInterface::DENY) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// Use the actual timestamp from an Expires header, if available.
|
||||
// The response passes all of the above checks, so cache it.
|
||||
// - Get the tags from CacheableResponseInterface per the earlier comments.
|
||||
// - Get the time expiration from the Expires header, rather than the
|
||||
// interface, but see https://www.drupal.org/node/2352009 about possibly
|
||||
// changing that.
|
||||
$tags = $response->getCacheableMetadata()->getCacheTags();
|
||||
$date = $response->getExpires()->getTimestamp();
|
||||
$expire = ($date > time()) ? $date : Cache::PERMANENT;
|
||||
|
||||
$tags = explode(' ', $response->headers->get('X-Drupal-Cache-Tags'));
|
||||
$this->set($request, $response, $expire, $tags);
|
||||
|
||||
// Mark response as a cache miss.
|
||||
|
|
|
@ -79,6 +79,37 @@ class PageCacheTest extends WebTestBase {
|
|||
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the page cache doesn't depend on cacheability headers.
|
||||
*/
|
||||
function testPageCacheTagsIndependentFromCacheabilityHeaders() {
|
||||
$this->setHttpResponseDebugCacheabilityHeaders(FALSE);
|
||||
|
||||
$path = 'system-test/cache_tags_page';
|
||||
$tags = array('system_test_cache_tags_page');
|
||||
$this->drupalGet($path);
|
||||
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
|
||||
|
||||
// Verify a cache hit, but also the presence of the correct cache tags.
|
||||
$this->drupalGet($path);
|
||||
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
|
||||
$cid_parts = array(\Drupal::url('system_test.cache_tags_page', array(), array('absolute' => TRUE)), 'html');
|
||||
$cid = implode(':', $cid_parts);
|
||||
$cache_entry = \Drupal::cache('render')->get($cid);
|
||||
sort($cache_entry->tags);
|
||||
$expected_tags = array(
|
||||
'config:user.role.anonymous',
|
||||
'pre_render',
|
||||
'rendered',
|
||||
'system_test_cache_tags_page',
|
||||
);
|
||||
$this->assertIdentical($cache_entry->tags, $expected_tags);
|
||||
|
||||
Cache::invalidateTags($tags);
|
||||
$this->drupalGet($path);
|
||||
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests support for different cache items with different request formats
|
||||
* specified via a query parameter.
|
||||
|
@ -418,22 +449,32 @@ class PageCacheTest extends WebTestBase {
|
|||
$config->set('cache.page.max_age', 300);
|
||||
$config->save();
|
||||
|
||||
// Try to fill the cache.
|
||||
// GET a URL, which would be marked as a cache miss if it were cacheable.
|
||||
$this->drupalGet('/system-test/respond-reponse');
|
||||
$this->assertFalse(in_array('X-Drupal-Cache', $this->drupalGetHeaders()), 'Drupal page cache header not found');
|
||||
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Drupal page cache header not found.');
|
||||
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'must-revalidate, no-cache, post-check=0, pre-check=0, private', 'Cache-Control header was sent');
|
||||
|
||||
// Still not cached, uncacheable response.
|
||||
// GET it again, verify it's still not cached.
|
||||
$this->drupalGet('/system-test/respond-reponse');
|
||||
$this->assertFalse(in_array('X-Drupal-Cache', $this->drupalGetHeaders()), 'Drupal page cache header not found');
|
||||
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Drupal page cache header not found.');
|
||||
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'must-revalidate, no-cache, post-check=0, pre-check=0, private', 'Cache-Control header was sent');
|
||||
|
||||
// Try to fill the cache.
|
||||
// GET a URL, which would be marked as a cache miss if it were cacheable.
|
||||
$this->drupalGet('/system-test/respond-public-response');
|
||||
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Drupal page cache header not found.');
|
||||
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'max-age=60, public', 'Cache-Control header was sent');
|
||||
|
||||
// GET it again, verify it's still not cached.
|
||||
$this->drupalGet('/system-test/respond-public-response');
|
||||
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Drupal page cache header not found.');
|
||||
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'max-age=60, public', 'Cache-Control header was sent');
|
||||
|
||||
// GET a URL, which should be marked as a cache miss.
|
||||
$this->drupalGet('/system-test/respond-cacheable-reponse');
|
||||
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.');
|
||||
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'max-age=300, public', 'Cache-Control header was sent.');
|
||||
|
||||
// Should be cached now.
|
||||
// GET it again, it should now be a cache hit.
|
||||
$this->drupalGet('/system-test/respond-cacheable-reponse');
|
||||
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.');
|
||||
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'max-age=300, public', 'Cache-Control header was sent.');
|
||||
|
@ -443,13 +484,9 @@ class PageCacheTest extends WebTestBase {
|
|||
$this->container->get('module_installer')
|
||||
->uninstall(['page_cache']);
|
||||
|
||||
// Try to fill the cache.
|
||||
$this->drupalGet('/system-test/respond-reponse');
|
||||
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'must-revalidate, no-cache, post-check=0, pre-check=0, private', 'Cache-Control header was sent');
|
||||
|
||||
// Still not cached, uncacheable response.
|
||||
$this->drupalGet('/system-test/respond-reponse');
|
||||
$this->assertEqual($this->drupalGetHeader('Cache-Control'), 'must-revalidate, no-cache, post-check=0, pre-check=0, private', 'Cache-Control header was sent');
|
||||
// GET a URL that was cached by Page Cache before, it should not be now.
|
||||
$this->drupalGet('/respond-cacheable-reponse');
|
||||
$this->assertFalse($this->drupalGetHeader('X-Drupal-Cache'), 'Drupal page cache header not found.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue