Tuesday, December 27, 2011

Clear cache programmatically in Drupal 5



This will reduce the work by going to performance settings page (admin/settings/performance) & clicking "cleared cached data" by scrolling down

But make sure that this page is only accessed by administrator


<?php
// only allow site administrators to visit this page:
if (!user_access('administer site configuration')) {
  drupal_not_found();
}else {
  drupal_clear_css_cache();
  $tables = array('cache','cache_content','cache_filter','cache_menu','cache_page',  'cache_views');
  foreach ($tables as $table) {
    cache_clear_all('*', $table, TRUE);
  }
  drupal_set_message('Cache cleared.');
  drupal_goto();
}
?>

No comments:

Post a Comment