1

Currently the max page cache age is 1 day. I would like to icnrease to 1 year. How can I do that?

These settings are located at /admin/config/development/performance

  • "Minimum cache lifetime"
  • "Expiration of cached pages"

Boost had a patch http://drupal.org/node/326683, wonder if this somehow could be applied for the core cache.

1
  • Which version of Drupal you are looking at ?
    – Anil Sagar
    Oct 4, 2012 at 9:07

2 Answers 2

5

Just set the variable 'page_cache_maximum_age' using variable_set in custom module to the value 31536000

variable_set('page_cache_maximum_age', 31536000);

If you install the Devel Module there is a page for viewing and editing variables.

Above is a quick fix. If you want to do a perfect way then you need to form alter the "system_performance" form and change the option of below field.

  $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']['cache_lifetime'] = array(
    '#type' => 'select',
    '#title' => t('Minimum cache lifetime'),
    '#default_value' => variable_get('cache_lifetime', 0),
    '#options' => $period,
    '#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.')
  );
3
  • Have you thought of releasing a mini module? If not and you're ok with it, I might release this code as a module called Increase Page Cache Maximum Age
    – giorgio79
    Oct 5, 2012 at 8:27
  • I am not sure community accepts as a mini module, since it's a small functionality. Yes, Give it a try :-) All the best !
    – Anil Sagar
    Oct 5, 2012 at 8:46
  • Be sure that variable_set ran once. If you run variable_set on every page load it will flush the cache. api.drupal.org/api/drupal/includes!bootstrap.inc/function/…
    – mikeytown2
    Oct 30, 2012 at 23:51
0

If you don't want to write a custom module, you can also set these values in your site's settings.php file:

$conf['cache_lifetime'] = 31536000;
$conf['page_cache_maximum_age'] = 31536000;

These values won't show up in the /admin/development/performance screen, so if you need to check the values in force, you can use drush:

> drush vget cache_lifetime
> drush vget page_cache_maximum_age

Or, go with @Anil-sagar's suggestion and implement an override to the system performance form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.