Issue #606840 by Wim Leers, cilefen, Fabianx, markpavlitski: Enable internal page cache by default

8.0.x
Alex Pott 2015-04-08 12:11:56 +01:00
parent fe6ef2a778
commit 25c41d0a6d
10 changed files with 105 additions and 21 deletions

View File

@ -17,7 +17,6 @@ use Symfony\Component\HttpFoundation\Request;
* @Plugin(
* id = \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationBrowser::METHOD_ID,
* weight = -2,
* cache = 0,
* name = @Translation("Browser"),
* description = @Translation("Language from the browser's language settings."),
* config_route_name = "language.negotiation_browser"
@ -36,6 +35,11 @@ class LanguageNegotiationBrowser extends LanguageNegotiationMethodBase {
public function getLangcode(Request $request = NULL) {
$langcode = NULL;
// Whenever browser-based language negotiation is used, the page cannot be
// cached by reverse proxies.
// @todo Solve more elegantly in https://www.drupal.org/node/2430335.
\Drupal::service('page_cache_kill_switch')->trigger();
if ($this->languageManager && $request && $request->server->get('HTTP_ACCEPT_LANGUAGE')) {
$http_accept_language = $request->server->get('HTTP_ACCEPT_LANGUAGE');
$langcodes = array_keys($this->languageManager->getLanguages());

View File

@ -141,7 +141,11 @@ class SessionTest extends WebTestBase {
* Test that empty anonymous sessions are destroyed.
*/
function testEmptyAnonymousSession() {
// Verify that no session is automatically created for anonymous user.
// Verify that no session is automatically created for anonymous user when
// page caching is disabled.
$config = $this->config('system.performance');
$config->set('cache.page.use_internal', 0);
$config->save();
$this->drupalGet('');
$this->assertSessionCookie(FALSE);
$this->assertSessionEmpty(TRUE);

View File

@ -49,6 +49,12 @@ class CronRunTest extends WebTestBase {
* need the exact time when cron is triggered.
*/
function testAutomaticCron() {
// Test with a logged in user; anonymous users likely don't cause Drupal to
// fully bootstrap, because of the internal page cache or an external
// reverse proxy. Reuse this user for disabling cron later in the test.
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
$this->drupalLogin($admin_user);
// Ensure cron does not run when the cron threshold is enabled and was
// not passed.
$cron_last = time();
@ -68,8 +74,6 @@ class CronRunTest extends WebTestBase {
$this->assertTrue($cron_last < \Drupal::state()->get('system.cron_last'), 'Cron runs when the cron threshold is passed.');
// Disable the cron threshold through the interface.
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
$this->drupalLogin($admin_user);
$this->drupalPostForm('admin/config/system/cron', array('cron_safe_threshold' => 0), t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
$this->drupalLogout();

View File

@ -5,6 +5,9 @@ user.register:
_title: 'Create new account'
requirements:
_access_user_register: 'TRUE'
# @todo Remove when https://www.drupal.org/node/2465053 lands.
options:
no_cache: TRUE
user.logout:
path: '/user/logout'

View File

@ -70,10 +70,23 @@ class GlossaryTest extends ViewTestBase {
// Enable the glossary to be displayed.
$view->storage->enable()->save();
$this->container->get('router.builder')->rebuildIfNeeded();
// Check the actual page response.
$this->drupalGet('glossary');
$this->assertResponse(200);
$url = Url::fromRoute('view.glossary.page_1');
// Verify cache tags.
$this->assertPageCacheContextsAndTags($url, ['languages:' . LanguageInterface::TYPE_CONTENT, 'languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'url', 'user.node_grants:view', 'user.permissions'], [
'config:views.view.glossary',
'node:' . $nodes_by_char['a'][0]->id(), 'node:' . $nodes_by_char['a'][1]->id(), 'node:' . $nodes_by_char['a'][2]->id(),
'node_list',
'user_list',
'rendered',
// FinishResponseSubscriber adds this cache tag to responses that have the
// 'user.permissions' cache context for anonymous users.
'config:user.role.anonymous',
]);
// Check the actual page response.
$this->drupalGet($url);
$this->assertResponse(200);
foreach ($nodes_per_char as $char => $count) {
$href = Url::fromRoute('view.glossary.page_1', ['arg_0' => $char])->toString();
$label = Unicode::strtoupper($char);
@ -85,19 +98,6 @@ class GlossaryTest extends ViewTestBase {
$result_count = trim(str_replace(array('|', '(', ')'), '', (string) $result[0]));
$this->assertEqual($result_count, $count, 'The expected number got rendered.');
}
// Verify cache tags.
$this->enablePageCaching();
$this->assertPageCacheContextsAndTags(Url::fromRoute('view.glossary.page_1'), ['languages:' . LanguageInterface::TYPE_CONTENT, 'languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'url', 'user.node_grants:view', 'user.permissions'], [
'config:views.view.glossary',
'node:' . $nodes_by_char['a'][0]->id(), 'node:' . $nodes_by_char['a'][1]->id(), 'node:' . $nodes_by_char['a'][2]->id(),
'node_list',
'user_list',
'rendered',
// FinishResponseSubscriber adds this cache tag to responses that have the
// 'user.permissions' cache context for anonymous users.
'config:user.role.anonymous',
]);
}
}

View File

@ -7,6 +7,7 @@
namespace Drupal\views\Tests\Plugin;
use Drupal\Core\Cache\Cache;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
@ -101,6 +102,14 @@ class AccessTest extends PluginTestBase {
// termination event fires. Simulate that here.
$this->container->get('router.builder')->rebuildIfNeeded();
// Clear the page cache.
// @todo Remove as part of https://www.drupal.org/node/2464657. The root
// cause is that the access plugins alters the route's access
// requirements. That means that the 403 from above does not have any
// cache tags, so modifying the View entity does not cause the cached 403
// page to be invalidated.
Cache::invalidateTags(['rendered']);
$this->assertTrue($access_plugin->access($this->normalUser));
$this->drupalGet('test_access_static');

View File

@ -0,0 +1,20 @@
cache:
page:
# @todo: Remove this file in https://www.drupal.org/node/2368987, update the
# install profile's YAML file to depend on the page_cache module instead.
use_internal: true
max_age: 0
css:
preprocess: true
gzip: true
fast_404:
enabled: true
paths: '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i'
exclude_paths: '/\/(?:styles|imagecache)\//'
html: '<!DOCTYPE html><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>'
js:
preprocess: true
gzip: true
response:
gzip: false
stale_file_threshold: 2592000

View File

@ -0,0 +1,20 @@
cache:
page:
# @todo: Remove this file in https://www.drupal.org/node/2368987, update the
# install profile's YAML file to depend on the page_cache module instead.
use_internal: true
max_age: 0
css:
preprocess: true
gzip: true
fast_404:
enabled: true
paths: '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i'
exclude_paths: '/\/(?:styles|imagecache)\//'
html: '<!DOCTYPE html><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>'
js:
preprocess: true
gzip: true
response:
gzip: false
stale_file_threshold: 2592000

View File

@ -0,0 +1,20 @@
cache:
page:
# @todo: Remove this file in https://www.drupal.org/node/2368987, update the
# install profile's YAML file to depend on the page_cache module instead.
use_internal: true
max_age: 0
css:
preprocess: true
gzip: true
fast_404:
enabled: true
paths: '/\.(?:txt|png|gif|jpe?g|css|js|ico|swf|flv|cgi|bat|pl|dll|exe|asp)$/i'
exclude_paths: '/\/(?:styles|imagecache)\//'
html: '<!DOCTYPE html><html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>'
js:
preprocess: true
gzip: true
response:
gzip: false
stale_file_threshold: 2592000

View File

@ -28,7 +28,7 @@ $config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;
/**
* Disable the render cache.
* Disable the render cache (this includes the page cache).
*
* This setting disables the render cache by using the Null cache back-end
* defined by the development.services.yml file above.