If you are using drush cc all
or clearing cache from the Performance page (admin/config/development/performance), then you end up calling drupal_flush_all_caches()
. This will
- Rebuilt the registry
- Clear CSS and JS caches
- Rebuild theme info
- Rebuild entity and field info
- Rebuilt the menu router table
- Rebuild the action list
- Clear all of the cache tables
The actual clearing of the cache tables is rather quick, but the other operations are pretty expensive. In addition, on the next page load (which can be when you get redirected back to the Performance page), you will rebuild all of the cache tables.
When I have seen cache clear problems, the root cause has normally been a misconfigured LAMP stack. Calculating out the max number of Apache processes to prevent system overload can help, as can having MySQL provisioned properly for buffers, max connections, etc.
In addition, in a live environment, you don't really need to rebuild everything from a drupal_flush_all_caches()
; you usually just want to clear the cache tables themselves. In this case, I use a variant of this:
/**
* Implements hook_form_FORM_ID_alter().
*/
function MYMODULE_form_system_performance_settings_alter(&$form, $form_state) {
$form['clear_cache']['clear_forward'] = array(
'#type' => 'submit',
'#value' => t('Clear all forward facing caches'),
'#submit' => array('MYMODULE_clear_forward_submit'),
);
}
function MYMODULE_clear_forward_submit($form, &$form_state) {
MYMODULE_clear_forward_caches();
}
function MYMODULE_clear_forward_caches() {
$cache_tables = array(
'cache',
'cache_block',
'cache_filter',
'cache_page',
'cache_views',
);
foreach ($cache_tables as $table) {
cache_clear_all('*', $table, TRUE);
}
drupal_set_message(t('Cleared forward facing caches.'));
}
This will add a new submit button to the Performance page which will just clear the caches that affect the forward facing portion of your website (ie, main pages). I wouldn't use this as is; you need to adjust the table list to match your environment. Once of these days I will make this more generic and release it as a public module.