12

Prior to D8 to clear cache manually one could truncate all tables beginning with cache_.

In Drupal 8 there are still tables starting with cache_, but there's also a cachetags table.

Is the advice in D8 still to truncate cache_* if you need to clear cache manually? Is it safe/required/recommended to truncate the cachetags table along with the cache_* tables?

I'm aware there may be contrib modules doing things differently, I'm mostly interested in what core does, and what's considered "best practice" for Drupal 8 in general.

6

In drupal 8 if you are looking for the safe tables that needs to be cleared manually then clear the tables starting with cache_ and also truncate the cachetags table too.

If you are using drush then use this command for clear cache-

drush cache-rebuild

3

According to this article cachetags are set when cache objects are being stored, so it should be safe to truncate this table also. Cachetags identify cache objects and you can get all related objects at once.

  • I tested and the table can be truncated without problems (or only with the potencial performance problem). It is recreated when the entity is loaded but... I don't know why if you delete a entity instance the tags saved in cachetags are already in the table. I thing that it has to be removed. – estoyausente Oct 14 '16 at 11:56
  • I assume data from cachetags table are removen on cron run and what you see after entity removal are just leftovers – Paul Bönisch Oct 14 '16 at 13:01
0

This is very handy. Replace dbname as needed:

DB_NAME="dbname"

mysql -uroot -proot --execute="SELECT concat('TRUNCATE TABLE ', TABLE_NAME, ';') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '${DB_NAME}' AND TABLE_NAME LIKE '%cache%'" | sed 1d | mysql -uroot -proot ${DB_NAME};
-1

In Drupal 8 it is save to clear cache_* & cache_* if you want to clear cache manually.

-2

All the cache tables are safe for truncating, didn't entirely remove them though.

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.