Update to Drupal 8.2.0. For more information, see https://www.drupal.org/project/drupal/releases/8.2.0

This commit is contained in:
Pantheon Automation 2016-10-06 15:16:20 -07:00 committed by Greg Anderson
parent 2f563ab520
commit f1c8716f57
1732 changed files with 52334 additions and 11780 deletions

View file

@ -7,6 +7,7 @@ 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;
@ -243,15 +244,34 @@ class PageCache implements HttpKernelInterface {
return $response;
}
// The response passes all of the above checks, so cache it.
$request_time = $request->server->get('REQUEST_TIME');
// The response passes all of the above checks, so cache it. Page cache
// entries default to Cache::PERMANENT since they will be expired via cache
// tags locally. Because of this, page cache ignores max age.
// - 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;
$this->set($request, $response, $expire, $tags);
$expire = 0;
// 403 and 404 responses can fill non-LRU cache backends and generally are
// likely to have a low cache hit rate. So do not cache them permanently.
if ($response->isClientError()) {
// Cache for an hour by default. If the 'cache_ttl_4xx' setting is
// set to 0 then do not cache the response.
$cache_ttl_4xx = Settings::get('cache_ttl_4xx', 3600);
if ($cache_ttl_4xx > 0) {
$expire = $request_time + $cache_ttl_4xx;
}
}
else {
$date = $response->getExpires()->getTimestamp();
$expire = ($date > $request_time) ? $date : Cache::PERMANENT;
}
if ($expire === Cache::PERMANENT || $expire > $request_time) {
$tags = $response->getCacheableMetadata()->getCacheTags();
$this->set($request, $response, $expire, $tags);
}
// Mark response as a cache miss.
$response->headers->set('X-Drupal-Cache', 'MISS');

View file

@ -3,11 +3,11 @@
namespace Drupal\page_cache\Tests;
use Drupal\Component\Datetime\DateTimePlus;
use Drupal\Core\Site\Settings;
use Drupal\Core\Url;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Cache\Cache;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
@ -130,15 +130,11 @@ class PageCacheTest extends WebTestBase {
$this->assertRaw('{"content":"oh hai this is json"}', 'The correct Json response was returned.');
// Enable REST support for nodes and hal+json.
\Drupal::service('module_installer')->install(['node', 'rest', 'hal']);
\Drupal::service('module_installer')->install(['node', 'rest', 'hal', 'basic_auth']);
$this->drupalCreateContentType(['type' => 'article']);
$node = $this->drupalCreateNode(['type' => 'article']);
$node_uri = $node->urlInfo();
$node_url_with_hal_json_format = $node->urlInfo('canonical')->setRouteParameter('_format', 'hal_json');
/** @var \Drupal\user\RoleInterface $role */
$role = Role::load('anonymous');
$role->grantPermission('restful get entity:node');
$role->save();
$this->drupalGet($node_uri);
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
@ -341,6 +337,7 @@ class PageCacheTest extends WebTestBase {
403 => $admin_url,
404 => $invalid_url,
];
$cache_ttl_4xx = Settings::get('cache_ttl_4xx', 3600);
foreach ($tests as $code => $content_url) {
// Anonymous user, without permissions.
$this->drupalGet($content_url);
@ -374,6 +371,35 @@ class PageCacheTest extends WebTestBase {
$this->drupalGet($content_url);
$this->assertResponse($code);
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
// Ensure the 'expire' field on the cache entry uses cache_ttl_4xx.
$cache_item = \Drupal::service('cache.render')->get($this->getUrl() . ':html');
$difference = $cache_item->expire - (int) $cache_item->created;
// Given that a second might have passed we cannot be sure that
// $difference will exactly equal the default cache_ttl_4xx setting.
// Account for any timing difference or rounding errors by ensuring the
// value is within 5 seconds.
$this->assertTrue(
$difference > $cache_ttl_4xx - 5 &&
$difference < $cache_ttl_4xx + 5,
'The cache entry expiry time uses the cache_ttl_4xx setting.'
);
}
// Disable 403 and 404 caching.
$settings['settings']['cache_ttl_4xx'] = (object) array(
'value' => 0,
'required' => TRUE,
);
$this->writeSettings($settings);
\Drupal::service('cache.render')->deleteAll();
foreach ($tests as $code => $content_url) {
// Getting the 404 page twice should still result in a cache miss.
$this->drupalGet($content_url);
$this->drupalGet($content_url);
$this->assertResponse($code);
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
}
}