How to clear only the front page cache? I want to clear the front page cache when a new node is added.


Drupal 6 and 7 use the URL of the page as the cache ID (the $cid, see drupal_page_set_cache()). This should work.

$url = url('<front>',  array('absolute' => TRUE));
cache_clear_all($url, 'cache_page');

You will need to adjust the logic a bit if you can access the site through multiple URLs.

| improve this answer | |

Give a try to Flush page cache module:

Flushing Drupal's cache on a large site can feel like you're waiting to takeoff on the tarmac at JFK. The delay comes from the fact that when you clear Drupal's cache, it clears everything. Most of time you just want to flush the cache for specific object on a page.The 'Flush page cache' module solves this problem by flushing only the cached objects for a single page. Additionally, you can define custom objects and cache tables to be cleared on specific pages

Use cases:

  • You have nodes nested in views nested in a panel page. You've edited a node that's displayed on this page, but you want the change to be seen immediately.
  • You have a large team of non-technical content editors who frequently run into the scenario above and you want to give them an easy, one-button solution to their content being updated in the lists they manage.
  • You've just cleared the entire website's cache through the normal means and for whatever reason, a few pages are rendered and cached in a broken state.
| improve this answer | |

Using drush is the fastest way to clear cache.

// clear all

drush cc all

// individual caches to clear

drush cc theme-registry

drush cc menu

drush cc css-js

drush cc block

drush cc registry

drush cc views

I found a blog post which shows how to clear a single page with drush. disclaimer I have not tried this method personally. Clear a single page cache drush

drush sqlq "DELETE FROM cache_page WHERE cid = 'http://example.com/'"

or with using a drush alias

drush @your_alias sqlq "DELETE FROM cache_page WHERE cid = 'http://example.com/'"
| improve this answer | |
  • -1. The question is to clear only the front page cache. – Sivaji Oct 20 '13 at 5:28
  • Clear a single page cache example clearly shows clearing the front page only and can be used for any particular page. Yes, I provided additional options to clear caches but is that against the rules at drupal stack exchange? – C13L0 Oct 20 '13 at 15:02
  • That should be added to comment. It is least relevant to consider it as an answer, IMO. – Sivaji Oct 28 '13 at 7:46
  • The question says "I want to clear the front page cache when a node is added." Clearing cache with drush doesn't help that use case. And using sql to clear the cache doesn't work if memcache is being used. – John Fiala Sep 3 '14 at 21:27
  • What happens when caching is handled by Varnish/Boost/nginx/etc ? – Christian Aug 3 '15 at 1:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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