Contextual module.links.action.yml – Caching problem

Hello everybody,

I am currently developing a module to create node-based user groups. (Yeah I know, there are already some other modules, but I have some other conditions)

For this there are action links on a defined Nodetype.
A button “apply” and a button “withdraw application”.
With the help of “_custom_access”, “apply” is displayed or “withdraw application” if an application already exists.
So far so good.

But there is a problem with the cache.
That as long as I do not delete the cache manually, the button “apply” is displayed, although I have just sent an application.
After clearing cache, “withdraw application” appears.

Should I delete the cache of the complete node in my Controller? Or is there a better solution for this?
And if I should delete the cache of this node. How can I do it?

module.routing.yml:

groups.group.apply:
  path: '/node/{node}/apply'
  defaults:
    _controller: 'DrupalgroupsControllerSubscriptionController::subscribe'
    _title: 'Apply'
  options:
    parameters:
      node:
        type: entity:node
  requirements:
    _permission: 'access content'
    _custom_access: 'DrupalgroupsControllerSubscriptionController::subscribeAccess'
    _csrf_token: 'TRUE'

groups.group.revoke:
  path: '/node/{node}/revoke'
  defaults:
    _controller: 'DrupalgroupsControllerSubscriptionController::revoke'
    _title: 'Revoke application'
  options:
    parameters:
      node:
        type: entity:node
  requirements:
    _permission: 'access content'
    _custom_access: 'DrupalgroupsControllerSubscriptionController::revokeAccess'
    _csrf_token: 'TRUE'

module.links.action.yml:

groups.group.apply:
  route_name: groups.group.apply
  title: 'Apply'
  weight: -20
  appears_on:
    - entity.node.canonical

groups.group.revoke:
  route_name: groups.group.revoke
  title: 'Revoke application'
  weight: -20
  appears_on:
    - entity.node.canonical
Drupal version: 


Source: https://www.drupal.org/taxonomy/term/4/feed