Drupal 8 Cache contexts | Drupal 8

Drupal 8 Cache contexts

Submitted by editor on Mon, 04/24/2017 - 13:00
Question

How to use drupal 8 cache contexts ?

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'];

 

 

Comments

keltan (not verified)

Thu, 05/11/2017 - 12:39

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

 

 

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.