Clearing the cache_block in Drupal 8.x I'm currently porting a Drupal module from 6.x -> 8.x. One of the lines in that module:


  cache_clear_all('##NAME_OF_THE_BLOCK##', 'cache_block', TRUE);


The cache_clear_all method does no longer exist in Drupal 8.x. I cannot find now where the 'cache_block' is situated. I'm looking for a way to flush this cache - and I don't want to flush 'all' cache ...

Any idea's what the D8 equivalent of this line is?
The D8 equivalent is cache tags and it kind of works in the reversed way.

What exactly is changing that requires you to invalidate the cache? Identify that, if it has a cache tag (e.g. a config object or an entity) then just make sure your block adds the cache tag for it and you're done.

To figure out if a cache tag invalidation happens, you can truncate the cachetags table, then make the change and check that table for new entries.

If there is no cache tag yet for that event, then you can define one yourself, add it to the render array or getCacheTags() of the block plugin and invalidate it with Cache::invalidateTags().

I would not recommend to do what @Clive suggested because unlike 7.x, your  block plugin (assuming it is a plugin not just one specific block instance) can be re-used many times, even with page_manager/panels.