I am running a Drupal 7 website with "Cache pages for anonymous users" and "Cache blocks" enabled. Both "Minimum cache lifetime" and "Expiration of cached pages" are set to 1 day.

When I update a node, for example, edit a picture, and visit that page as an anonymous user, the new picture isn't being displayed. When I manually clear the cache the page is displayed as it should be. It's like the cache isn't cleared after the node is updated.

Extract of the API:


function node_form_submit($form, &$form_state) {
  $node = node_form_submit_build_node($form, $form_state);
  $insert = empty($node->nid);

  // Do stuff...

  // Clear the page and block caches.

Notice that the function cache_clear_all is called after the node is saved, regardless if the node needs to be inserted or updated.

Further inspection of the API reveals the following:


function node_save($node) {


    // Save the node and node revision.
    if ($node->is_new) {
      drupal_write_record('node', $node);
    else {


    // Clear the static loading cache.


Again, everything seems to be as it should be. The cache is cleared using the Entity API (public DrupalDefaultEntityController::resetCache(array $ids = NULL)).

Nothing seems to be wrong in the code. Maybe the code doesn't clear all of the necessary cache?


The problem is that you have a minimum lifetime of 1 day set. This means cache_clear_all() will not remove entries with a lifetime of less than a day. Try setting this to 1 hour, or something more acceptable for your site (eg, how long between new content or edited content, and when an anonymous user needs to see the content).


You can use db_delete() to clear the db table "manually" regardless of minimum lifetime.

Your Answer

