0

I changed services.yml file (i use dynamic cache):

renderer.config:
required_cache_contexts: ['languages:language_interface', 'theme', 'user.permissions', 'cookies:Drupal.visitor.Country']

And sey the cookie properly with an event:

$events[KernelEvents::REQUEST][] = ['checkCountry', 30];
...
 user_cookie_save(['Country' => $country]);

I checked and the cookie is saved correctly. But the cache does not work...

2

Anonymous page cache does not respect cache contexts, I'm guessing that is your problem.

To get that working, you need to switch out the PageCache service in a custom module with a ServiceProvider and override the getCacheId() method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.