Event subscriber to invalidate a cache
I did it implementing a middleware:

mymodule/mymodule.services.yml:

mymodule.http_middleware:
  class: Drupal\mymodule\StackMiddleware\BeforePageCache
  arguments:
    - '@cache_tags.invalidator'
  tags:
    - { name: http_middleware, priority: 280, responder: true }


mymodule/src/StackMiddleware/BeforePageCache.php

...
/**
 * {@inheritdoc}
 */
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
  if ($request-&gt;cookies-&gt;has('myValue')) {
    $this-&gt;cacheTagsInvalidator-&gt;invalidateTags(['my_tag']);
  }

  return $this-&gt;httpKernel-&gt;handle($request, $type, $catch);
}
...