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:NAMEheaders:NAMEiplanguages:TYPErequest_formatroute.book_navigationroute.menu_active_trails:MENU_NAMEroute.namesession.existsthemetimezoneurl.path.is_fronturl.path.parenturl.query_args:KEYurl.query_args.pagers:PAGER_IDurl.siteuser.is_super_useruser.node_grants:OPERATIONSuser.permissionsuser.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