Invalidate block cache programmatically I have a block that is cached per page. However, I need a way to invalidate it's cache in code per page or node. (Or, if no way, all cache per block id).
The SystemMenuBlock of core is invalidated when its menu changes because this method:

public function getCacheTags() {
  // Even when the menu block renders to the empty string for a user, we want
  // the cache tag for this menu to be set: whenever the menu is changed, this
  // menu block must also be re-rendered for that user, because maybe a menu
  // link that is accessible for that user has been added.
  $cache_tags = parent::getCacheTags();
  $cache_tags[] = 'config:system.menu.' . $this-&gt;getDerivativeId();
  return $cache_tags;
}


I think you can solve your problem in the same way.