Force Rebuild of Custom Entity's Task Menu My module has a custom entity along with custom menu tasks. I would like the tasks shown for a specific entity to be dependent on its properties. Once the properties change I would like the task menu to refresh. 

I use custom permissions to determine which menu tabs to show.

I have tried to invalidate the entity's tags after a user changes properties but the task menu does not change (I don't see the permissions being checked again either).

\Drupal\Core\Cache\Cache::invalidateTags(array(
        '[my_custom_entity_type]:' . $entity-&gt;id()
)


If I clear all caches, the entity's menu changes as needed but that is a very expensive operation.

Would love some help.
After days of painful searching and reading code, I figured it out on my own. It was super easy once I got it. Since I am using a custom permissions handler to determine if a user should see an entity's task, I added cache tags to the AccessResult object that the custom handler returns:

$cache_tags = array('my_custom_entity_type:' . $my_custom_entity-&gt;id());

$access_forbidden = AccessResult::forbidden()-&gt;addCacheTags($cache_tags);


Later when my custom entity changes, I invalidate the tag(s) in the submitForm() function of my custom forms:

\Drupal\Core\Cache\Cache::invalidateTags(array('my_custom_entity_type:' . $my_custom_entity-&gt;id());