28 April 2023

The snippet shows how to clear Drupal 10 cache programmatically. You can do that for all of the cache or one by one using the ID of the cache that you want to clear.

Source code viewer
  1. \Drupal::cache()->invalidateAll();
  3. // One by one.
  4. \Drupal::cache('cache.backend.mysql')->deleteAll(); // clear MySQL cache
  5. \Drupal::cache('cache.page')->deleteAll(); // clear page cache
  6. \Drupal::cache('cache.entity')->deleteAll(); // clear entity cache
Programming Language: PHP