diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 8fde8aac944defd527eabf8cc00569426edb7b69..0d07356c7f928a55b8228c73edabf2026f599ce3 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2328,7 +2328,7 @@ function _drupal_bootstrap_page_cache() { else { drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES, FALSE); $config = config('system.performance'); - $cache_enabled = $config->get('cache.page.enabled'); + $cache_enabled = $config->get('cache.page.use_internal'); } // If there is no session cookie and cache is enabled (or forced), try // to serve a cached page. diff --git a/core/includes/form.inc b/core/includes/form.inc index 7e374055f243abf9031e67ee10793864afa9a0cd..3ebaca1a5f18ab6b94b4018b0a9fba94640074ff 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -920,7 +920,7 @@ function drupal_process_form($form_id, &$form, &$form_state) { // here, as we've finished with them. The in-memory copies are still // here, though. $config = config('system.performance'); - if (!$config->get('cache.page.enabled') && !empty($form_state['values']['form_build_id'])) { + if (!$config->get('cache.page.use_internal') && !empty($form_state['values']['form_build_id'])) { cache('form')->delete('form_' . $form_state['values']['form_build_id']); cache('form')->delete('form_state_' . $form_state['values']['form_build_id']); } diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index f29e0b01378824a3ac790eadd7a1a889a595c04c..c5c491c842e03ca934f6bf956581fc974e17727f 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -91,7 +91,8 @@ public function onRespond(FilterResponseEvent $event) { // use partial page caching more extensively. // Commit the user session, if needed. drupal_session_commit(); - if (config('system.performance')->get('cache.page.enabled') && ($cache = drupal_page_set_cache($response->getContent()))) { + $max_age = config('system.performance')->get('cache.page.max_age'); + if ($max_age > 0 && ($cache = drupal_page_set_cache($response->getContent()))) { drupal_serve_page_from_cache($cache); // drupal_serve_page_from_cache() already printed the response. $response->setContent(''); diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php index 4cb7053c2f90d390ff0ebf5e9064ed2cd23aaa4e..286ad7139303a3017defbe564ef2ef409d61701e 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php @@ -48,7 +48,8 @@ function setUp() { // Enable page caching. $config = config('system.performance'); - $config->set('cache.page.enabled', 1); + $config->set('cache.page.use_internal', 1); + $config->set('cache.page.max_age', 300); $config->save(); // Enable access logging. diff --git a/core/modules/system/config/system.performance.yml b/core/modules/system/config/system.performance.yml index d508591d7e57530506780cd7128b43e7b0fe1d5a..80f349a1b5d9a5ac53d745ab7de3f4a972ffd68c 100644 --- a/core/modules/system/config/system.performance.yml +++ b/core/modules/system/config/system.performance.yml @@ -1,6 +1,6 @@ cache: page: - enabled: '0' + use_internal: '0' max_age: '0' css: preprocess: '0' diff --git a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookExitTest.php b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookExitTest.php index 06733409d7399a51423a2a06d2671c3a71d71c11..0a8ef18831e555d49c0efe26d5734b7d4f126be0 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookExitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/HookExitTest.php @@ -35,7 +35,7 @@ public static function getInfo() { function testHookExit() { // Test with cache disabled. Exit should always fire. $config = config('system.performance'); - $config->set('cache.page.enabled', 0); + $config->set('cache.page.use_internal', 0); $config->save(); $this->drupalGet(''); @@ -44,7 +44,8 @@ function testHookExit() { // Test with normal cache. On the first call, exit should fire // (since cache is empty), but on the second call it should not be fired. - $config->set('cache.page.enabled', 1); + $config->set('cache.page.use_internal', 1); + $config->set('cache.page.max_age', 300); $config->save(); $this->drupalGet(''); $calls++; diff --git a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php index 92c0dce40c559f79a96b8dbe2905777a848be320..c09576cd9a914a6588632f22e071d39e9303cdff 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php @@ -43,7 +43,8 @@ function setUp() { */ function testConditionalRequests() { $config = config('system.performance'); - $config->set('cache.page.enabled', 1); + $config->set('cache.page.use_internal', 1); + $config->set('cache.page.max_age', 300); $config->save(); // Fill the cache. @@ -87,14 +88,15 @@ function testConditionalRequests() { */ function testPageCache() { $config = config('system.performance'); - $config->set('cache.page.enabled', 1); + $config->set('cache.page.use_internal', 1); + $config->set('cache.page.max_age', 300); $config->save(); // Fill the cache. $this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar'))); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS', 'Page was not cached.'); $this->assertEqual($this->drupalGetHeader('Vary'), 'Cookie,Accept-Encoding', 'Vary header was sent.'); - $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'public, max-age=0', 'Cache-Control header was sent.'); + $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'public, max-age=300', 'Cache-Control header was sent.'); $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.'); $this->assertEqual($this->drupalGetHeader('Foo'), 'bar', 'Custom header was sent.'); @@ -102,7 +104,7 @@ function testPageCache() { $this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar'))); $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT', 'Page was cached.'); $this->assertEqual($this->drupalGetHeader('Vary'), 'Cookie,Accept-Encoding', 'Vary: Cookie header was sent.'); - $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'public, max-age=0', 'Cache-Control header was sent.'); + $this->assertEqual($this->drupalGetHeader('Cache-Control'), 'public, max-age=300', 'Cache-Control header was sent.'); $this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.'); $this->assertEqual($this->drupalGetHeader('Foo'), 'bar', 'Custom header was sent.'); @@ -133,7 +135,8 @@ function testPageCache() { */ function testPageCompression() { $config = config('system.performance'); - $config->set('cache.page.enabled', 1); + $config->set('cache.page.use_internal', 1); + $config->set('cache.page.max_age', 300); $config->save(); // Fill the cache and verify that output is compressed. diff --git a/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php b/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php index dadd2f28d403c8fd3b9b2621fd18c127fab945a0..53a443e798578be860d4ebe496b8e125b91b70a3 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Session/SessionTest.php @@ -148,7 +148,8 @@ function testEmptyAnonymousSession() { // The same behavior is expected when caching is enabled. $config = config('system.performance'); - $config->set('cache.page.enabled', 1); + $config->set('cache.page.use_internal', 1); + $config->set('cache.page.max_age', 300); $config->save(); $this->drupalGet(''); $this->assertSessionCookie(FALSE); diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php index 7d0d29f1a0cd225505edebc1e459ef485e755585..73a2977dc4e2a9d8594e52fa83f0e2298c327f7f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/SystemUpgradePathTest.php @@ -50,7 +50,7 @@ public function testVariableUpgrade() { ); $expected_config['system.performance'] = array( - 'cache.page.enabled' => '1', + 'cache.page.use_internal' => '1', 'cache.page.max_age' => '1800', 'response.gzip' => '1', 'js.preprocess' => '1', diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index f66fd2e4dbb7178019274b216f52456647e385ca..a2c7011d51844c445e77f00d3bcef539be3b94d1 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -1651,21 +1651,21 @@ function system_performance_settings($form, &$form_state) { '#title' => t('Caching'), ); - $form['caching']['cache'] = array( - '#type' => 'checkbox', - '#title' => t('Cache pages for anonymous users'), - '#default_value' => $config->get('cache.page.enabled'), - '#weight' => -2, - ); - $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval'); $period[0] = '<' . t('none') . '>'; $form['caching']['page_cache_maximum_age'] = array( '#type' => 'select', - '#title' => t('Expiration of cached pages'), + '#title' => t('Page cache maximum age'), '#default_value' => $config->get('cache.page.max_age'), '#options' => $period, - '#description' => t('The maximum time an external cache can use an old version of a page.'), + '#description' => t('The maximum time a page can be cached. This is used as the value for max-age in Cache-Control headers.'), + ); + + $form['caching']['cache'] = array( + '#type' => 'checkbox', + '#title' => t('Use internal page cache'), + '#description' => t("If a reverse proxy cache isn't available, use Drupal's internal cache system to store cached pages."), + '#default_value' => $config->get('cache.page.use_internal'), ); $directory = 'public://'; @@ -1682,7 +1682,7 @@ function system_performance_settings($form, &$form_state) { '#description' => t('External resources can be optimized automatically, which can reduce both the size and number of requests made to your website.') . $disabled_message, ); - $js_hide = $config->get('cache.page.enabled') ? '' : ' class="js-hide"'; + $js_hide = ($config->get('cache.page.max_age') > 0) ? '' : ' class="js-hide"'; $form['bandwidth_optimization']['page_compression'] = array( '#type' => 'checkbox', '#title' => t('Compress cached pages.'), @@ -1724,7 +1724,7 @@ function system_performance_settings($form, &$form_state) { function system_performance_settings_submit($form, &$form_state) { config_context_enter('config.context.free'); $config = config('system.performance'); - $config->set('cache.page.enabled', $form_state['values']['cache']); + $config->set('cache.page.use_internal', $form_state['values']['cache']); $config->set('cache.page.max_age', $form_state['values']['page_cache_maximum_age']); $config->set('response.gzip', $form_state['values']['page_compression']); $config->set('css.preprocess', $form_state['values']['preprocess_css']); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index d8674bb12e82ef44fca6ed30d4e70aed19d64575..daac6bade694ca40d246d1d4ce92af7621999d63 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1585,7 +1585,7 @@ function system_update_8016() { */ function system_update_8017() { update_variables_to_config('system.performance', array( - 'cache' => 'cache.page.enabled', + 'cache' => 'cache.page.use_internal', 'page_cache_maximum_age' => 'cache.page.max_age', 'page_compression' => 'response.gzip', 'preprocess_css' => 'css.preprocess',