Tuesday, December 18, 2012

Flush drupal cache from code

Hey everyone,

Today I would like to share how to recover a blank drupal website using cache clear. Most of the times we change our websites from one server to another. In drupal when we do that our database tables and files messes the cache settings. But while this is happening in database your websites goes blank or it goes unreachable so in that case you have to run one drupal function which will help you to rebuild the registry, rebuild the menu, rebuild the path.

All you need to do is put the code either on page--front.tpl.php or on page.tpl.php.


<?php
// This will Change query-strings on css/js files to enforce reload for all users. 
  _drupal_flush_css_js(); 

  registry_rebuild();     //To rebuild module data
  drupal_clear_css_cache(); //This will flushes the cached css
  drupal_clear_js_cache(); //This will flushes the cached js
?> 


Remember that do not put this code in any if else condition just put it either on page.tpl.php or on front page of your drupal site. And then hit the URL in any browser. Then our code will get executed. Our code would then flush the js and css for all users. Then it would rebuild the registry of all modules. Then it would clear the css cache and then js cache.
So now this would defiantly bring the drupal site back on its feet. 

Thanks for reading.

Enjoy & Be Open

2 comments:

  1. bro, i would like you to contribute to my blog.
    www. linuxosr . blogspot. com (remove spaces).
    it would be very great of your contribution. in response, you can mention your blog link to the post you make on my blog.
    thank you.
    if u r interested, u can contact me
    linuxworld7@gmail.com

    ReplyDelete
  2. Thanks but my solutions are FREE you can copy & paste it on your blog :)

    ReplyDelete