Skip to main content
added 124 characters in body
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

@Leigh is right and user does exist. Cache contexts are hierarchical (see change record https://www.drupal.org/node/2451661) and user is a top level context.

So this should work (note the plural form of contexts):

  '#cache' => [
    'contexts' => ['user'],

You can also add the cache context by IDE autocompleting:

$response->getCacheableMetadata()->addCacheContexts(['user']);

@Leigh is right and user does exist. Cache contexts are hierarchical (see change record https://www.drupal.org/node/2451661) and user is a top level context.

So this should work (note the plural form of contexts):

  '#cache' => [
    'contexts' => ['user'],

@Leigh is right and user does exist. Cache contexts are hierarchical (see change record https://www.drupal.org/node/2451661) and user is a top level context.

So this should work (note the plural form of contexts):

  '#cache' => [
    'contexts' => ['user'],

You can also add the cache context by IDE autocompleting:

$response->getCacheableMetadata()->addCacheContexts(['user']);
Source Link
4uk4
  • 101.7k
  • 7
  • 173
  • 217

@Leigh is right and user does exist. Cache contexts are hierarchical (see change record https://www.drupal.org/node/2451661) and user is a top level context.

So this should work (note the plural form of contexts):

  '#cache' => [
    'contexts' => ['user'],