hook_flush_caches

6 core.php hook_flush_caches()
7 system.api.php hook_flush_caches()

Add a list of cache tables to be cleared.

This hook allows your module to add cache table names to the list of cache tables that will be cleared by the Clear button on the Performance page or whenever drupal_flush_all_caches is invoked.

Parameters

None.:

Return value

An array of cache table names.

See also

drupal_flush_all_caches()

system_clear_cache_submit()

Related topics

2 functions implement hook_flush_caches()

2 invocations of hook_flush_caches()

File

developer/hooks/core.php, line 2691
These are the hooks that are invoked by the Drupal core.

Code

function hook_flush_caches() {
  return array('cache_example');
}

Comments

Note

This hook is also invoked on every cron run by system_cron(), so it may be called a lot more often than you'd think.

The right hook tu use for all kinds of cache ?

I have developed a module that needs to manage a kind of file cache (the files being cached come from a distant web service) and I want this cache to be cleard by an administrator according to his will.

The name of the hook, "hook_flush_caches", seems to allow me to use it for the file cache flush purpose. But the description says its use is restricted to the table cache.

So, what kinds of cache this hook is really allowed to manage ?

Using hook_flush_caches for file based caches

If you take update_flush_caches() as an example an empty array is returned and a "custom" cache function _update_cache_clear() is run to replace the core implementation of a db cache flush.

I'm sure you could implement something similar in that vein. If anything the description of the scope of what can be achieved with this function appears to be too limited, or at least inconsistent with how other core modules are implementing their own caches.

http://api.drupal.org/api/drupal/modules%21update%21update.module/group/... actually implies that for any type of caching that is necessarily not as volatile as individual pageviews on your site, you should use this hook and implement your own cache logic there.

However, that doesn't mean that if you're implementing a file based cache engine to be a drop-in replacement for the db engine that you should rewrite the whole thing here :P

Login or register to post comments