Commit 47653eae authored by Dries's avatar Dries

- Patch #730046 by pwolanin, Damien Tournoud: performance settings page is inconsistent.

parent a60a608e
...@@ -48,16 +48,6 @@ ...@@ -48,16 +48,6 @@
*/ */
define('CACHE_TEMPORARY', -1); define('CACHE_TEMPORARY', -1);
/**
* Indicates that page caching is disabled.
*/
define('CACHE_DISABLED', 0);
/**
* Indicates that page caching is enabled, using "normal" mode.
*/
define('CACHE_NORMAL', 1);
/** /**
* Log message severity -- Emergency: system is unusable. * Log message severity -- Emergency: system is unusable.
* *
...@@ -1096,7 +1086,7 @@ function drupal_serve_page_from_cache(stdClass $cache) { ...@@ -1096,7 +1086,7 @@ function drupal_serve_page_from_cache(stdClass $cache) {
// do not bother caching the page in a public proxy, because the cached copy // do not bother caching the page in a public proxy, because the cached copy
// will only be served to that particular user due to Vary: Cookie, unless // will only be served to that particular user due to Vary: Cookie, unless
// the Vary header has been replaced or unset in hook_boot() (see below). // the Vary header has been replaced or unset in hook_boot() (see below).
$max_age = !variable_get('page_cache_invoke_hooks', TRUE) && (!isset($_COOKIE[session_name()]) || isset($hook_boot_headers['vary'])) ? variable_get('cache_lifetime', 0) : 0; $max_age = !variable_get('page_cache_invoke_hooks', TRUE) && (!isset($_COOKIE[session_name()]) || isset($hook_boot_headers['vary'])) ? variable_get('page_cache_maximum_age', 0) : 0;
$default_headers['Cache-Control'] = 'public, max-age=' . $max_age; $default_headers['Cache-Control'] = 'public, max-age=' . $max_age;
// Entity tag should change if the output changes. // Entity tag should change if the output changes.
...@@ -1982,16 +1972,16 @@ function _drupal_bootstrap_page_cache() { ...@@ -1982,16 +1972,16 @@ function _drupal_bootstrap_page_cache() {
} }
// Check for a cache mode force from settings.php. // Check for a cache mode force from settings.php.
if (variable_get('page_cache_without_database')) { if (variable_get('page_cache_without_database')) {
$cache_mode = CACHE_NORMAL; $cache_enabled = TRUE;
} }
else { else {
drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES, FALSE); drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES, FALSE);
$cache_mode = variable_get('cache'); $cache_enabled = variable_get('cache');
} }
drupal_block_denied(ip_address()); drupal_block_denied(ip_address());
// If there is no session cookie and cache is enabled (or forced), try // If there is no session cookie and cache is enabled (or forced), try
// to serve a cached page. // to serve a cached page.
if (!isset($_COOKIE[session_name()]) && $cache_mode == CACHE_NORMAL) { if (!isset($_COOKIE[session_name()]) && $cache_enabled) {
// Make sure there is a user object because it's timestamp will be // Make sure there is a user object because it's timestamp will be
// checked, hook_boot might check for anonymous user etc. // checked, hook_boot might check for anonymous user etc.
$user = drupal_anonymous_user(); $user = drupal_anonymous_user();
......
...@@ -2431,7 +2431,7 @@ function drupal_page_footer() { ...@@ -2431,7 +2431,7 @@ function drupal_page_footer() {
// Commit the user session, if needed. // Commit the user session, if needed.
drupal_session_commit(); drupal_session_commit();
if (variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED && ($cache = drupal_page_set_cache())) { if (variable_get('cache', 0) && ($cache = drupal_page_set_cache())) {
drupal_serve_page_from_cache($cache); drupal_serve_page_from_cache($cache);
} }
else { else {
......
...@@ -651,7 +651,7 @@ function drupal_process_form($form_id, &$form, &$form_state) { ...@@ -651,7 +651,7 @@ function drupal_process_form($form_id, &$form, &$form_state) {
// We'll clear out the cached copies of the form and its stored data // We'll clear out the cached copies of the form and its stored data
// here, as we've finished with them. The in-memory copies are still // here, as we've finished with them. The in-memory copies are still
// here, though. // here, though.
if (variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED && !empty($form_state['values']['form_build_id'])) { if (!variable_get('cache', 0) && !empty($form_state['values']['form_build_id'])) {
cache_clear_all('form_' . $form_state['values']['form_build_id'], 'cache_form'); cache_clear_all('form_' . $form_state['values']['form_build_id'], 'cache_form');
cache_clear_all('storage_' . $form_state['values']['form_build_id'], 'cache_form'); cache_clear_all('storage_' . $form_state['values']['form_build_id'], 'cache_form');
} }
......
...@@ -283,7 +283,7 @@ function language_provider_invoke($provider_id, $provider = NULL) { ...@@ -283,7 +283,7 @@ function language_provider_invoke($provider_id, $provider = NULL) {
// If the language provider has no cache preference or this is satisfied // If the language provider has no cache preference or this is satisfied
// we can execute the callback. // we can execute the callback.
$cache = !isset($provider['cache']) || $user->uid || $provider['cache'] == variable_get('cache', CACHE_DISABLED); $cache = !isset($provider['cache']) || $user->uid || $provider['cache'] == variable_get('cache', 0);
$callback = isset($provider['callbacks']['language']) ? $provider['callbacks']['language'] : FALSE; $callback = isset($provider['callbacks']['language']) ? $provider['callbacks']['language'] : FALSE;
$langcode = $cache && function_exists($callback) ? $callback($languages) : FALSE; $langcode = $cache && function_exists($callback) ? $callback($languages) : FALSE;
$results[$provider_id] = isset($languages[$langcode]) ? $languages[$langcode] : FALSE; $results[$provider_id] = isset($languages[$langcode]) ? $languages[$langcode] : FALSE;
......
...@@ -151,7 +151,7 @@ function hook_language_negotiation_info() { ...@@ -151,7 +151,7 @@ function hook_language_negotiation_info() {
'types' => array('custom_language_type'), 'types' => array('custom_language_type'),
'name' => t('Custom language provider'), 'name' => t('Custom language provider'),
'description' => t('This is a custom language provider.'), 'description' => t('This is a custom language provider.'),
'cache' => CACHE_DISABLED, 'cache' => 0,
), ),
); );
} }
......
...@@ -589,7 +589,7 @@ function locale_language_negotiation_info() { ...@@ -589,7 +589,7 @@ function locale_language_negotiation_info() {
'callbacks' => array('language' => 'locale_language_from_browser'), 'callbacks' => array('language' => 'locale_language_from_browser'),
'file' => $file, 'file' => $file,
'weight' => -2, 'weight' => -2,
'cache' => CACHE_DISABLED, 'cache' => 0,
'name' => t('Browser'), 'name' => t('Browser'),
'description' => t("Determine the language from the browser's language settings."), 'description' => t("Determine the language from the browser's language settings."),
); );
......
...@@ -375,7 +375,7 @@ class PollVoteCheckHostname extends PollTestCase { ...@@ -375,7 +375,7 @@ class PollVoteCheckHostname extends PollTestCase {
// Enable page cache to verify that the result page is not saved in the // Enable page cache to verify that the result page is not saved in the
// cache when anonymous voting is allowed. // cache when anonymous voting is allowed.
variable_set('cache', CACHE_NORMAL); variable_set('cache', 1);
// Create poll. // Create poll.
$title = $this->randomName(); $title = $this->randomName();
......
...@@ -105,7 +105,7 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase { ...@@ -105,7 +105,7 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase {
* Test support for requests containing If-Modified-Since and If-None-Match headers. * Test support for requests containing If-Modified-Since and If-None-Match headers.
*/ */
function testConditionalRequests() { function testConditionalRequests() {
variable_set('cache', CACHE_NORMAL); variable_set('cache', 1);
// Fill the cache. // Fill the cache.
$this->drupalGet(''); $this->drupalGet('');
...@@ -143,7 +143,7 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase { ...@@ -143,7 +143,7 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase {
* Test cache headers. * Test cache headers.
*/ */
function testPageCache() { function testPageCache() {
variable_set('cache', CACHE_NORMAL); variable_set('cache', 1);
// Fill the cache. // Fill the cache.
$this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar'))); $this->drupalGet('system-test/set-header', array('query' => array('name' => 'Foo', 'value' => 'bar')));
...@@ -187,7 +187,7 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase { ...@@ -187,7 +187,7 @@ class BootstrapPageCacheTestCase extends DrupalWebTestCase {
* mod_deflate Apache module. * mod_deflate Apache module.
*/ */
function testPageCompression() { function testPageCompression() {
variable_set('cache', CACHE_NORMAL); variable_set('cache', 1);
// Fill the cache and verify that output is compressed. // Fill the cache and verify that output is compressed.
$this->drupalGet('', array(), array('Accept-Encoding: gzip,deflate')); $this->drupalGet('', array(), array('Accept-Encoding: gzip,deflate'));
...@@ -280,14 +280,14 @@ class HookBootExitTestCase extends DrupalWebTestCase { ...@@ -280,14 +280,14 @@ class HookBootExitTestCase extends DrupalWebTestCase {
*/ */
function testHookBootExit() { function testHookBootExit() {
// Test with cache disabled. Boot and exit should always fire. // Test with cache disabled. Boot and exit should always fire.
variable_set('cache', CACHE_DISABLED); variable_set('cache', 0);
$this->drupalGet(''); $this->drupalGet('');
$calls = 1; $calls = 1;
$this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, t('hook_boot called with disabled cache.')); $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, t('hook_boot called with disabled cache.'));
$this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, t('hook_exit called with disabled cache.')); $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_exit'))->fetchField(), $calls, t('hook_exit called with disabled cache.'));
// Test with normal cache. Boot and exit should be called. // Test with normal cache. Boot and exit should be called.
variable_set('cache', CACHE_NORMAL); variable_set('cache', 1);
$this->drupalGet(''); $this->drupalGet('');
$calls++; $calls++;
$this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, t('hook_boot called with normal cache.')); $this->assertEqual(db_query('SELECT COUNT(*) FROM {watchdog} WHERE type = :type AND message = :message', array(':type' => 'system_test', ':message' => 'hook_boot'))->fetchField(), $calls, t('hook_boot called with normal cache.'));
......
...@@ -140,7 +140,7 @@ class SessionTestCase extends DrupalWebTestCase { ...@@ -140,7 +140,7 @@ class SessionTestCase extends DrupalWebTestCase {
$this->assertSessionEmpty(TRUE); $this->assertSessionEmpty(TRUE);
// The same behavior is expected when caching is enabled. // The same behavior is expected when caching is enabled.
variable_set('cache', CACHE_NORMAL); variable_set('cache', 1);
$this->drupalGet(''); $this->drupalGet('');
$this->assertSessionCookie(FALSE); $this->assertSessionCookie(FALSE);
$this->assertSessionEmpty(TRUE); $this->assertSessionEmpty(TRUE);
......
...@@ -1622,12 +1622,12 @@ function system_performance_settings() { ...@@ -1622,12 +1622,12 @@ function system_performance_settings() {
'#title' => t('Caching'), '#title' => t('Caching'),
); );
$cache = variable_get('cache', CACHE_DISABLED); $cache = variable_get('cache', 0);
$form['caching']['cache'] = array( $form['caching']['cache'] = array(
'#type' => 'radios', '#type' => 'checkbox',
'#title' => t('Page cache for anonymous users'), '#title' => t('Cache pages for anonymous users'),
'#default_value' => $cache, '#default_value' => $cache,
'#options' => array(CACHE_DISABLED => t('Disabled'), CACHE_NORMAL => t('Normal (recommended)')), '#weight' => -2,
); );
$period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval'); $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') . '>'; $period[0] = '<' . t('none') . '>';
...@@ -1636,7 +1636,14 @@ function system_performance_settings() { ...@@ -1636,7 +1636,14 @@ function system_performance_settings() {
'#title' => t('Minimum cache lifetime'), '#title' => t('Minimum cache lifetime'),
'#default_value' => variable_get('cache_lifetime', 0), '#default_value' => variable_get('cache_lifetime', 0),
'#options' => $period, '#options' => $period,
'#description' => t('The minimum amount of time that will elapse before the caches are recreated.') '#description' => t('Cached pages will not be re-created until at least this much time has elapsed.')
);
$form['caching']['page_cache_maximum_age'] = array(
'#type' => 'select',
'#title' => t('Expiration of cached pages'),
'#default_value' => variable_get('page_cache_maximum_age', 0),
'#options' => $period,
'#description' => t('The maximum time an external cache can use an old version of a page.')
); );
$directory = 'public://'; $directory = 'public://';
...@@ -1653,7 +1660,7 @@ function system_performance_settings() { ...@@ -1653,7 +1660,7 @@ function system_performance_settings() {
'#description' => t('External resources can be optimized automatically, which can reduce both the size and number of requests made to your website.') . $disabled_message, '#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 = $cache == CACHE_DISABLED ? ' class="js-hide"' : ''; $js_hide = $cache ? '' : ' class="js-hide"';
$form['bandwidth_optimization']['page_compression'] = array( $form['bandwidth_optimization']['page_compression'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Compress cached pages.'), '#title' => t('Compress cached pages.'),
......
...@@ -1995,7 +1995,7 @@ function system_update_7032() { ...@@ -1995,7 +1995,7 @@ function system_update_7032() {
*/ */
function system_update_7033() { function system_update_7033() {
if (variable_get('cache') == 2) { if (variable_get('cache') == 2) {
variable_set('cache', CACHE_NORMAL); variable_set('cache', 1);
return t('Aggressive caching was disabled and replaced with normal caching. Read the page caching section in default.settings.php for more information on how to enable similar functionality.'); return t('Aggressive caching was disabled and replaced with normal caching. Read the page caching section in default.settings.php for more information on how to enable similar functionality.');
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment