Can any of the cache_* be emptied safely?

Sometimes when moving the database it can be too large. Can any of the "cache_" prefixed tables be emptied without causing problems?

Answers 4

  • With one exception, yes. That exception is cache_form. That is not actually a cache table but contains temporary $form_state information of forms currently displayed on your site. Clearing that table would invalidate these forms and when a user then tries to submit that form, he will get an error message and has to fill out that form again.

    Note that drush sql-dump and Backup and Migrate automatically leave out the content of these and other tables when creating a database dump with these instead of mysqldump or phpmyadmin.


  • There's a "false friend" in that list. cache_form is not a cache table, and emptying it will invalidate all forms active on the site at that moment.

    I also don't see a reason why you would use phpmyadmin for this. It is clunky and error prone. "drush cc all" is your friend :)


  • The purpose of the cache tables is keeping computed values. When a module calls cache_get(), and it gets back an empty value, then it just executes the code to obtain back the cached values.
    All the modules I know automatically execute the code to get the value they were expecting in the cache, if the cache is empty; emptying the cache doesn't cause any problem to the modules using it.


  • I have done it many times and haven't find any problem by doing it.

    Important notice - try to clear all cache tables at once. This will prevent Drupal from using invalid cache data.


Related Questions