Quantcast
Channel: Niluka Blog » Cron
Viewing all articles
Browse latest Browse all 3

Drupal 7 boost clear all cache

$
0
0

In Drupal 7 when clicking clear cache button, all boost cache also clean.

Find the boost_flush_caches() in boost.module and comment

if (isset($_boost['base_dir']) && (lock_may_be_available(‘cron’) || variable_get(‘boost_ignore_flush’, BOOST_IGNORE_FLUSH) == FALSE)) {
$count = _boost_rmdir($_boost['base_dir'], TRUE);
watchdog(‘boost’, ‘Flushed all files (%count) from static page cache.’, array(‘%count’ => $count), WATCHDOG_NOTICE);

Final code :

/**
* Implements hook_flush_caches(). Deletes all static files.
*/
function boost_flush_caches() {
	// Remove all files from the cache
	global $_boost;

	// This may not have been invoked in hook_init because of the quick
	// check to avoid caching requests from the CLI
	$_boost = boost_transform_url();

	// The lock_may_be_available() checks to see if the flush was requested by
	// the core cron, since we may want to ignore it (boost_ignore_flush)
	//desable clear boost cache wehen cear drupal cache by niluka 2013-03-22
	/*if (isset($_boost['base_dir']) && (lock_may_be_available('cron') || variable_get('boost_ignore_flush', BOOST_IGNORE_FLUSH) == FALSE)) {
	$count = _boost_rmdir($_boost['base_dir'], TRUE);
	watchdog('boost', 'Flushed all files (%count) from static page cache.', array('%count' => $count), WATCHDOG_NOTICE);
	}*/
	//end comment
	return;
}

Now write a form alter function for add a new button to below clear cache button,

/**
* simple function to clear all bost cache
*/
function hook_form_alter(&$form, &$form_state, $form_id) {
	if ($form_id=='system_performance_settings') {
		$form['clearboostcache'] = array(
			'#type' => 'fieldset',
			'#title' => t('Boost clear cache'),
		);
		$form['clearboostcache']['clear_all_cache'] = array(
			'#type' => 'submit',
			'#value' => t('Clear all boost cache'),
			'#submit' => array('sample_form_submit_one'),
		);
	}
}

function sample_form_submit_one(&$form, &$form_state){
	global $_boost;

	// This may not have been invoked in hook_init because of the quick
	// check to avoid caching requests from the CLI
	$_boost = boost_transform_url();

	// The lock_may_be_available() checks to see if the flush was requested by
	// the core cron, since we may want to ignore it (boost_ignore_flush)

	if (isset($_boost['base_dir']) && (lock_may_be_available('cron') || variable_get('boost_ignore_flush', BOOST_IGNORE_FLUSH) == FALSE)) {
		$count = _boost_rmdir($_boost['base_dir'], TRUE);
		watchdog('boost', 'Flushed all files (%count) from static page cache.', array('%count' => $count), WATCHDOG_NOTICE);
		drupal_set_message(t('Flushed all files '.$count.' from static page cache.'), 'status');
	}

	return;
}

enjoy.. !!! :)



Viewing all articles
Browse latest Browse all 3

Trending Articles