Skip to main content
Add core link to existing context to avoid confusion
Source Link
leymannx
  • 18.8k
  • 6
  • 72
  • 126

There's the cookies and cookies:MY_COOKIE_NAME cache context from core. Now I need to invalidate the Internal Page Cache for anonymous users when the value of a specific cookie changes. How can I implement this?

I'mI tried to add:

$build['#cache']['contexts'][] = 'cookies:my-cookie-name'MY_COOKIE_NAME'

in hook_entity_build_defaults_alter, but that doesn't help. And and the page still returns from the cache.

I need to invalidate the Internal Page Cache for anonymous users when the value of a specific cookie changes. How can I implement this?

I'm tried to add:

$build['#cache']['contexts'][] = 'cookies:my-cookie-name'

in hook_entity_build_defaults_alter, but that doesn't help. And the page still returns from the cache.

There's the cookies and cookies:MY_COOKIE_NAME cache context from core. Now I need to invalidate the Internal Page Cache for anonymous users when the value of a specific cookie changes. How can I implement this?

I tried to add:

$build['#cache']['contexts'][] = 'cookies:MY_COOKIE_NAME'

in hook_entity_build_defaults_alter, but that doesn't help and the page still returns from the cache.

Tweeted twitter.com/StackDrupal/status/1145799243082412035
Source Link
qzmenko
  • 180
  • 1
  • 9

Invalidate Internal Page Cache on cookie change

I need to invalidate the Internal Page Cache for anonymous users when the value of a specific cookie changes. How can I implement this?

I'm tried to add:

$build['#cache']['contexts'][] = 'cookies:my-cookie-name'

in hook_entity_build_defaults_alter, but that doesn't help. And the page still returns from the cache.