Caching for anonymous users set to expire after a minute, but it never expires: any idea what I'm doing wrong?

Events happening in the community are now at Drupal community events on www.drupal.org.
alberto56's picture

I am expecting my pages to be cached for anonymous users for a maximum of one minute, but there is probably something I am not understanding. Any help greatly appreciated!

To reproduce:

Install a new Drupal 7 site

On admin/config/development/performance,

  • set Cache pages for anonymous users to checked
  • set Cache blocks to checked
  • set Minimum cache lifetime to 1 minute
  • set Expiration of cached pages to 1 minute

now download the examples proejct and enable the block_example module.

in block_example.module, add a line under function block_example_contents, like this:

<?php
function block_example_contents($which_block) {
  return array(
'#markup' => REQUEST_TIME);
?>

now go to admin/structure/block and set "Example: configurable text string" to "sidebar first"

Log out and go to the home page

Reload the page several times -- the block is cached, as expected for one minute. (You see the same time for a minute)

However, the block stays cached for more than one minute (I tried until 2 minutes and the time never changes)

I would expect the time on the page to change after 1 minute, because the cache is expired.

if set Cache blocks is unchecked, the behaviour is identical.

I was under the impression that the page cache for anonymous users would expire after one minute if Minimum cache lifetime is set to 1 minute.

How can set a set a maximum lifetime for my anonymous page cache?

Comments

Core Cache

mikeytown2's picture

The Page Cache in drupal gets cleared on cron. If you follow the code path the expire field never gets checked against the time. I would try out Alternative Database Cache it might give you the results your expecting; although I see it doesn't have it's own implementation of prepareItem so it might not.

_drupal_bootstrap_page_cache -> drupal_page_get_cache -> cache_get -> _cache_get_object -> DrupalDatabaseCache::get -> DrupalDatabaseCache::getMultiple ->
DrupalDatabaseCache::prepareItem

More info

mikeytown2's picture

Looking into the code for ADBC and it does implement it's own version of garbageCollection; when compared to core I believe the ADBC module will do what you need.

@mikeytown2 thanks for your

alberto56's picture

@mikeytown2 thanks for your response. I'll maybe try to call the page clearing function via cron every minute.

High performance

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: