3

I need to invalidate the block list cache each time a new configuration entity is created, this is because I have a derivative block to handle dynamically one block for each of my configuration entities. I tried to invalidate the block list with the following code

Drupal\Core\Cache\Cache::invalidateTags(['block_list']);

But when I go to see available blocks I'm not able to see my new block until I clean all the caches on the site.

Usually, when I need to invalidate entity lists from the cache I use the ENTITY-NAME_list tag to do it but this time is not working, maybe I'm missing something here?

3

Clearing the cache not only invalidates the render cache, but also a lot of other caches. For example all plugin manager discovery caches.

In this case you probably need to invalidate the cache of the block plugin manager:

\Drupal::service('plugin.manager.block')->clearCachedDefinitions();
1
  • Nice answer, I will keep this in mind for the future. – Adrian Cid Almaguer Jun 22 at 18:04

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.