It is actually pretty simple.
For your implementation of
hook_flush_caches, all you need to do is return an array containing the names of your cache tables, eg
function mymodule_flush_caches ()
drupal_flush_all_caches and cache_clear_all take care of the rest.
drupal_flush_all_caches is called anytime you manually clear the cache (the perforamnce page, admin menu, drush, etc). system_cron does get called by cron, and also clears the cache tables, but does not do some of the other things that
When you get something out of the cache with
cache_get, expired items will have already been removed from the cache; you don't need to manually check expirations. They will be handled automatically according to how you put them in the cache with