How to use drupal 8 cache contexts ?
Question
Drupal 8 shiped with a powerfull cache API able to set cache according to a context. correct usage of this cache improve the site preformence greatly.
https://www.drupal.org/docs/8/api/cache-api/cache-contexts
https://www.drupal.org/node/2451661
Cache contexts
cookies:NAME
headers:NAME
ip
languages:TYPE
request_format
route.book_navigation
route.menu_active_trails:MENU_NAME
route.name
session.exists
theme
timezone
url.path.is_front
url.path.parent
url.query_args:KEY
url.query_args.pagers:PAGER_ID
url.site
user.is_super_user
user.node_grants:OPERATIONS
user.permissions
user.roles:ROLE
Example 1 - URL :
$output['#cache']['max-age'] = 3600; // 3600 = 1h
$output['#cache']['contexts'] = ['url'];
Example 2 - User :
$output['#cache']['max-age'] = 3600; // 3600 = 1h
$output['#cache']['contexts'] = ['user'];
Comments1
Great Post
I'm very inspired with this weblog. this indicates it literally does not have any dietary cost and consuming it virtually makes your body use up stored nutrients to method it. last time I visit write my essay this website also awesome Honey then again has many useful nutrients, enzymes, and antioxidants; uncooked honey is first-class as standard honey processing