This may not be suitable for everyone, and may not be quick enough for the OP — as it is only triggered on the next page initialisation. However, it helped me with triggering code just after a "cache clear all" that wasn't time sensitive.
Obviously HOOK
needs replacing with your own module name.
/**
* Implements hook_init().
*/
function HOOK_init(){
// if there is no cache_not_empty defined, define it
// and then trigger our cache cleared code
if ( !cache_get('HOOK_cache_not_empty') ) {
cache_set('HOOK_cache_not_empty', TRUE);
foreach (module_implements('cache_cleared') as $module) {
module_invoke($module, 'cache_cleared');
}
}
}
/**
* Implements hook_cache_cleared().
*/
function HOOK_cache_cleared(){
// do what you need here, in which ever module.
}
If you have a specific bin you need to target, the above could be modified to support that, as long as the entire bin gets emptied at the point of your cache clear.
hook_init
is only executed for non-cached pages. Although because a full cache clear should mean no cached pages, this shouldn't cause a problem. However, external caching systems like Varnish will get in the way of this triggering, and will mean it'll only occur when the next proper request reaches back to Drupal.
It should also be noted that depending on your caching system — on exactly when a cache_set
becomes available to all concurrent users — that this hook could be triggered multiple times concurrently, especially if you have large numbers of users.