I am currently building a module using a custom REST resource plugin for Taxonomy Terms using the name field of the term rather than referencing the tid field. Everything works fine but drupal_flush_all_caches() function return is slow. I've tried working with a few caches as per documentation:

drupal_static_reset();
\Drupal::service('plugin.cache_clearer')->clearCachedDefinitions();
\Drupal::service("cache.data")->deleteAll();
\Drupal::service("cache.render")->deleteAll();

$cache = \Drupal::cache('data');
$cache->deleteAll();

$cache = \Drupal::cache('render');
$cache->deleteAll();

However, only drupal_flush_all_caches() actually works. Does anyone have recommendations of which cache to target which produces a cache rebuild which is faster than 6 seconds and better suited to taxonomy terms?

Comments

slewazimuth’s picture

This code is what I used as a kludge for my use case:

use Drupal\Core\Cache\Cache; // added to plugin before class declaration

//just before end of patch function

foreach (Cache::getBins() as $service_id => $cache_backend) {
if($service_id == 'render' || $service_id == 'entity')
$cache_backend->deleteAll();
}

If anyone has something better, excellent! (I'll be continuing to search for faster code)