1

I'm using drupal 6 and I've build table that is similar to cache (hook_schema) for using it with function cache_get/cache_set. I just want to be sure how things should work in drupal.

  1. To clean the table I'll need to use hook hook_flush_caches() where I'll decide if i want to clear expire data or whole cache? hook_flush_caches is called on cron?
  2. In case I'll need to check data expiration by second, I'll need to do manually after cache_get function ?

This is kinda confusing...

1 Answer 1

3

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 ()
{
  return array("cache_mymodule");
}

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 drupal_flush_all_caches does.

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 cache_set.

That's it.

1
  • 1
    I missed "hook_flush_caches" :( Thanks!
    – confiq
    Jan 23, 2012 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.