15

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.

3

4 Answers 4

8

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

0
5

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.

2
  • 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. Oct 14, 2016 at 11:56
  • I assume data from cachetags table are removen on cron run and what you see after entity removal are just leftovers Oct 14, 2016 at 13:01
2

You could do this for a one-liner:

drush sqlq "TRUNCATE cache_default;TRUNCATE cache_bootstrap;TRUNCATE cache_container;TRUNCATE cache_discovery;TRUNCATE cache_data;" -l <uri> --no-interaction

Add as many with cache_ prefix as you would like.

1

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};

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.