Score:3

How to invalidate the block list cache?

cn flag

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?

Score:3
cn flag

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();
cn flag
Nice answer, I will keep this in mind for the future.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.