cacheflush.inc in CacheFlush 7
Same filename and directory in other branches
Cacheflusher module inc file with dinamic clear cache functions.
File
cacheflush.incView source
<?php
/**
* @file
* Cacheflusher module inc file with dinamic clear cache functions.
*/
/**
* Clear all caches function.
*/
function _cacheflush_clear_all() {
// Clear all caches.
drupal_flush_all_caches();
drupal_set_message(t('All caches cleared.'));
drupal_goto($_SERVER['HTTP_REFERER']);
}
/**
* Based on settings decide witch clear cache function to be called.
*
* @param int $preset_id
* Preset id to do clear cache for.
*/
function _cacheflush_clear_preset($preset_id) {
// Get presets.
$cache_presets = variable_get('cacheflush_preset_list', array());
// Decide if is table or function and call specifed function to clear cache.
foreach ($cache_presets[$preset_id]['#cacheflush_preset_values'] as $key => $value) {
if ($value['is_table']) {
_cacheflush_clear_preset_clear_table($key, $value);
}
else {
_cacheflush_clear_preset_clear_call_functions($value);
}
}
drupal_set_message(t("@name preset caches cleared.", array(
'@name' => $cache_presets[$preset_id]['#name'],
)));
drupal_goto($_SERVER['HTTP_REFERER']);
}
/**
* Function to clear cache from a specific table.
*
* @param string $table
* Table name.
* @param array $settings
* Preset setting with cache clear functions.
*/
function _cacheflush_clear_preset_clear_table($table, $settings) {
// If is advanced preset clear by settings else clear all table.
if (isset($settings['query'])) {
cache_clear_all($settings['query']['cid'], $settings['query']['table'], $settings['query']['wildcard'] ? TRUE : FALSE);
}
else {
cache_clear_all('*', $table, TRUE);
}
}
/**
* Call predefined functions to clear cache.
*
* @param array $settings
* Preset setting with cache clear functions.
*/
function _cacheflush_clear_preset_clear_call_functions($settings) {
// Call every function declared in preset.
foreach ($settings['functions'] as $value) {
$value();
}
}
Functions
Name | Description |
---|---|
_cacheflush_clear_all | Clear all caches function. |
_cacheflush_clear_preset | Based on settings decide witch clear cache function to be called. |
_cacheflush_clear_preset_clear_call_functions | Call predefined functions to clear cache. |
_cacheflush_clear_preset_clear_table | Function to clear cache from a specific table. |