I'm writing a custom module to extend the Casetracker module to allow users to update the cases' due date via the comments form. So far I have successfully used hook_form_comment_form() to add the date field to the comment form and hook_comment() to write the new value to the DB using drupal_write_record().

I'm running into a caching problem though. The updated values don't show up in the node until I drush cc all. Is there a way I can tell Drupal to update it's cache to show the new value?

I'm using Drupal 6.26, Casetracker 6.x-1.0-beta9 (part of OpenAtrium).


you can use cache_clear_all() to clear the caches after you write the new value to the database. it will be best if you can find out the comment's cache id and clear only that one. Unfortunately I don't have any D6 databases on my server to look into the database

  • cache_clear_all() without arguments didn't work, but looking through the cache tables I found the right table and cache id. In this case the table is cache_content and $cid = 'content: . $nid . ':' . $vid. So calling cache_clear_all($cid,'cache_content'); get's the job done without flushing the entire cache.
    – aweizd
    Jul 9 '12 at 9:07
  • yup, that's the one. good job :) Jul 9 '12 at 13:45

You could add the drupal_flush_all_caches() function in order to do a complete cache clear.

But if you know which tables to be cleared you can use cache_clear_all('*', 'TABLE_TO_FLUSH', TRUE);. This is better for performance reasons.

Cache_clear_all could be confusing because actually, it doesn't clear all caches by default.

// Empties cache tables, rebuilds the menu cache and theme registries, and invokes a hook so that other modules' cache data can be cleared as well.

// If called without arguments, expirable entries will be cleared from the cache_page and cache_block bins.
  • drupal_flush_all_caches does work, but I can see the performance implications. My solution is cache_clear_all($cid,'cache_content'); where $cid = 'content: . $nid . ':' . $vid.
    – aweizd
    Jul 9 '12 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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