SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
Drupal Day 2020 – Drupal
Cache Systems and Varnish
Pedro Dias
November 2020
2
Drupal cache out
of the box
Internal Dynamic Page CacheInternal Page Caching
3
Every request constructs the output Saves the whole HTML for a given page,
useful for a website with anonymous
visitors
Caches page components instead of the
whole page, avoids a component to be
computed in every requests if it behaves
the same for all the pages
Cache turned off
Drupal out of the box caching systems
4
Drupal out of the box caching systems
What is cacheable in
Drupal?
—Every renderable element
Cache Max-ageCache Contexts
5
• A way of tagging a cacheable element
used for bulk invalidation.
• Used to create cache related elements
• When a cache tag is invalidated, all
elements with that tag are invalidated
• Appliable to all renderable elements
• Custom ones can be created
• Provides a way of storing cache
contextualized with the incoming
request
• Analogous to HTTP's Vary header.
• Provides the ability for different users
to see different cached content
• Appliable to all renderable elements
• Custom ones can be created
• Instructs the time to live of the
renderable element cache
Cacheability Metadata in Drupal
Cache Tags
6
Cacheability Metadata in Drupal
7
Enhance Drupal
with Varnish
Enhance Drupal with Varnish
8
What is Varnish?
- HTTP Accelerator known as HTTP Reverse
Proxy
- Stores the generated HTML for a given URL
and serves the request without hitting the
webserver
- Speeds up delivery with a factor of 300 -
1000x
Enhance Drupal with Varnish
9
Drupal and Varnish
- Installing Drupal Varnish Cache Contrib
module give the ability to integrate with
Cache Tags.
- Drupal + Varnish out-of-the-box work like
Drupal Internal Page Cache
- Same cache for every visitors
Icons made by Freepick from www.flaticon.com
Enhance Drupal with Varnish
10
Having Drupal + Varnish Installed
Contextual response example
• Our users have a attribute called “Has car”
• We want to deliver different content to the user based on this
attribute
• Cache contexts won’t work
Enhance Drupal with Varnish
11
Means that we cannot serve content
based on the request context?
• Out of the box no, Varnish caches pages based on the URL
• Varnish offers a Vary mechanism to make cache be contextual for
the request (Same logic as Drupal Cache-Contexts)
• Varnish can be instructed by webserver response how the cache
varies using the response Vary header
• Vary header should contain which request headers should be
used to store the cache based on their combinations
• For our example we need to add the request header that contains
the attribute value to make it vary
Enhance Drupal with Varnish – Initial state
12
Icons made by Freepick from www.flaticon.com
Enhance Drupal with Varnish – Adding the CDN
13
Icons made by Freepick from www.flaticon.com
Enhance Drupal with Varnish – Make Info about car available on client-side
14
Icons made by Freepick from www.flaticon.com
Enhance Drupal with Varnish – Add the cookie value as a Request header by CDN
15
Icons made by Freepick from www.flaticon.com
Enhance Drupal with Varnish – Make cache Vary by X-Has-Car header
16
Icons made by Freepick from www.flaticon.com
Enhance Drupal with Varnish - Summary
17
Summary
• Value needed for cache to Vary passed to client side using a
cookie
• Leverage the use of a CDN to transform a cookie into a Request
Header
• Drupal instructs Varnish to Vary cache based on that header
Icons made by Freepick from www.flaticon.com
Enhance Drupal with Varnish – Combine with Cache contexts
18
Combine Varnish and Drupal cache
• Cache contexts continue to make sense in reusable components
• Enhances performance on shared components
• Pages in which the content is different from the path should use
the before explained mechanism
Enhance Drupal with Varnish
19
Tips to handle cache problems
• Remember that the first hit is always cached
• Setup http.response.debug_cacheability_headers in services.yml
and check X-Drupal-Cache-Contexts
• For debugging Varnish you can pass all the request headers
started to X to the response
20
Thank you!

Weitere ähnliche Inhalte

Was ist angesagt?

Scaling wordpress for high traffic
Scaling wordpress for high trafficScaling wordpress for high traffic
Scaling wordpress for high traffic
Roshan Bhattarai
 
Roshan Bhattarai: Scaling WordPress for high traffic sites
Roshan Bhattarai: Scaling WordPress for high traffic sitesRoshan Bhattarai: Scaling WordPress for high traffic sites
Roshan Bhattarai: Scaling WordPress for high traffic sites
wpnepal
 
Redis e Memcached - Daniel Naves - Omnilogic
Redis e Memcached - Daniel Naves - OmnilogicRedis e Memcached - Daniel Naves - Omnilogic
Redis e Memcached - Daniel Naves - Omnilogic
Felipe Guimarães
 
WordPress: Performance, Optimization & Scaling
WordPress: Performance, Optimization & ScalingWordPress: Performance, Optimization & Scaling
WordPress: Performance, Optimization & Scaling
Pete Mall
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
drupalcampest
 
Php & web server performace
Php & web server performacePhp & web server performace
Php & web server performace
Tuyển Đoàn
 

Was ist angesagt? (19)

IWMW 1997: WWW Caching
IWMW 1997: WWW CachingIWMW 1997: WWW Caching
IWMW 1997: WWW Caching
 
RESTful Web services in Drupal 8
RESTful Web services in Drupal 8RESTful Web services in Drupal 8
RESTful Web services in Drupal 8
 
IWMW 1997: Database-WWW Integration
IWMW 1997: Database-WWW IntegrationIWMW 1997: Database-WWW Integration
IWMW 1997: Database-WWW Integration
 
Scaling wordpress for high traffic
Scaling wordpress for high trafficScaling wordpress for high traffic
Scaling wordpress for high traffic
 
Roshan Bhattarai: Scaling WordPress for high traffic sites
Roshan Bhattarai: Scaling WordPress for high traffic sitesRoshan Bhattarai: Scaling WordPress for high traffic sites
Roshan Bhattarai: Scaling WordPress for high traffic sites
 
Ch08
Ch08Ch08
Ch08
 
Redis e Memcached - Daniel Naves - Omnilogic
Redis e Memcached - Daniel Naves - OmnilogicRedis e Memcached - Daniel Naves - Omnilogic
Redis e Memcached - Daniel Naves - Omnilogic
 
Comparison of Drupal and WordPress
Comparison of Drupal and WordPressComparison of Drupal and WordPress
Comparison of Drupal and WordPress
 
0812 2014 01_toronto-smac meetup_i_os_cloudant_worklight_part2
0812 2014 01_toronto-smac meetup_i_os_cloudant_worklight_part20812 2014 01_toronto-smac meetup_i_os_cloudant_worklight_part2
0812 2014 01_toronto-smac meetup_i_os_cloudant_worklight_part2
 
Site building using Drupal 8
Site building using Drupal 8Site building using Drupal 8
Site building using Drupal 8
 
WordPress: Performance, Optimization & Scaling
WordPress: Performance, Optimization & ScalingWordPress: Performance, Optimization & Scaling
WordPress: Performance, Optimization & Scaling
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
 
Dynamic Website
Dynamic Website Dynamic Website
Dynamic Website
 
Sitebuildingdrupal 8
Sitebuildingdrupal 8Sitebuildingdrupal 8
Sitebuildingdrupal 8
 
High Performance Drupal
High Performance DrupalHigh Performance Drupal
High Performance Drupal
 
Php & web server performace
Php & web server performacePhp & web server performace
Php & web server performace
 
Dynamic Website Designing
Dynamic Website DesigningDynamic Website Designing
Dynamic Website Designing
 
Optimize drupal
Optimize drupalOptimize drupal
Optimize drupal
 
Front End development of biological database
Front End development of biological databaseFront End development of biological database
Front End development of biological database
 

Ähnlich wie DRUPAL CACHE SYSTEMS AND VARNISH

Drupal is not your Website
Drupal is not your Website Drupal is not your Website
Drupal is not your Website
Phase2
 
The Need for Speed - EpiCenter 2010
The Need for Speed - EpiCenter 2010The Need for Speed - EpiCenter 2010
The Need for Speed - EpiCenter 2010
Phil Pursglove
 
Showcasing drupal
Showcasing drupalShowcasing drupal
Showcasing drupal
Opevel
 
Case study - Nuskin: Statefull Applications in a Stateless World
Case study - Nuskin: Statefull Applications in a Stateless WorldCase study - Nuskin: Statefull Applications in a Stateless World
Case study - Nuskin: Statefull Applications in a Stateless World
Day Software
 

Ähnlich wie DRUPAL CACHE SYSTEMS AND VARNISH (20)

Tips To Increase The Speed Of Drupal 8 Websites
Tips To Increase The Speed Of Drupal 8 WebsitesTips To Increase The Speed Of Drupal 8 Websites
Tips To Increase The Speed Of Drupal 8 Websites
 
Advanced Drupal 8 Caching
Advanced Drupal 8 CachingAdvanced Drupal 8 Caching
Advanced Drupal 8 Caching
 
Varnish intro
Varnish introVarnish intro
Varnish intro
 
Drupal performance optimization Best Practices
Drupal performance optimization Best PracticesDrupal performance optimization Best Practices
Drupal performance optimization Best Practices
 
Decoupling Drupal - Drupal Camp Toronto 2014
Decoupling Drupal - Drupal Camp Toronto 2014Decoupling Drupal - Drupal Camp Toronto 2014
Decoupling Drupal - Drupal Camp Toronto 2014
 
Html Optimization for SEO
Html Optimization for SEOHtml Optimization for SEO
Html Optimization for SEO
 
Make Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speedMake Drupal Run Fast - increase page load speed
Make Drupal Run Fast - increase page load speed
 
Building faster websites: web performance with WordPress
Building faster websites: web performance with WordPressBuilding faster websites: web performance with WordPress
Building faster websites: web performance with WordPress
 
In-Fisherman.com - Building an Enterprise Level Drupal Site
In-Fisherman.com - Building an Enterprise Level Drupal SiteIn-Fisherman.com - Building an Enterprise Level Drupal Site
In-Fisherman.com - Building an Enterprise Level Drupal Site
 
Drupal 8 and NGINX
Drupal 8 and NGINX Drupal 8 and NGINX
Drupal 8 and NGINX
 
PHP Performance tuning for Drupal 8
PHP Performance tuning for Drupal 8PHP Performance tuning for Drupal 8
PHP Performance tuning for Drupal 8
 
Drupal is not your Website
Drupal is not your Website Drupal is not your Website
Drupal is not your Website
 
Contentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshopContentful with Netgen Layouts workshop
Contentful with Netgen Layouts workshop
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalability
 
Optimizing Drupal Performance (English)
Optimizing Drupal Performance (English)Optimizing Drupal Performance (English)
Optimizing Drupal Performance (English)
 
The Need for Speed - EpiCenter 2010
The Need for Speed - EpiCenter 2010The Need for Speed - EpiCenter 2010
The Need for Speed - EpiCenter 2010
 
Phil Pursglove: Velocity, the Need for Speed - epicenter 2010
Phil Pursglove: Velocity, the Need for Speed - epicenter 2010Phil Pursglove: Velocity, the Need for Speed - epicenter 2010
Phil Pursglove: Velocity, the Need for Speed - epicenter 2010
 
Showcasing drupal
Showcasing drupalShowcasing drupal
Showcasing drupal
 
Case study - Nuskin: Statefull Applications in a Stateless World
Case study - Nuskin: Statefull Applications in a Stateless WorldCase study - Nuskin: Statefull Applications in a Stateless World
Case study - Nuskin: Statefull Applications in a Stateless World
 
Ror caching
Ror cachingRor caching
Ror caching
 

Mehr von Drupal Portugal

Mehr von Drupal Portugal (18)

DRUPAL DIGITAL MARKETING CHECKLIST
DRUPAL DIGITAL MARKETING CHECKLISTDRUPAL DIGITAL MARKETING CHECKLIST
DRUPAL DIGITAL MARKETING CHECKLIST
 
Drupal Day Portugal 2020 - Closing Remarks / Encerramento
Drupal Day Portugal 2020 - Closing Remarks / EncerramentoDrupal Day Portugal 2020 - Closing Remarks / Encerramento
Drupal Day Portugal 2020 - Closing Remarks / Encerramento
 
BRANCHING MODELS (workshop)
BRANCHING MODELS (workshop)BRANCHING MODELS (workshop)
BRANCHING MODELS (workshop)
 
TURN YOUR DRUPAL INTO A DIGITAL EXPERIENCE PLATFORM (DXP)
TURN YOUR DRUPAL INTO A DIGITAL EXPERIENCE PLATFORM (DXP)TURN YOUR DRUPAL INTO A DIGITAL EXPERIENCE PLATFORM (DXP)
TURN YOUR DRUPAL INTO A DIGITAL EXPERIENCE PLATFORM (DXP)
 
COMO CRIAR O TEU STARTUP PROJECT E SETUP DO TEU AMBIENTE DE DESENVOLVIMENTO D...
COMO CRIAR O TEU STARTUP PROJECT E SETUP DO TEU AMBIENTE DE DESENVOLVIMENTO D...COMO CRIAR O TEU STARTUP PROJECT E SETUP DO TEU AMBIENTE DE DESENVOLVIMENTO D...
COMO CRIAR O TEU STARTUP PROJECT E SETUP DO TEU AMBIENTE DE DESENVOLVIMENTO D...
 
Drupal Day Portugal 2020
Drupal Day Portugal 2020Drupal Day Portugal 2020
Drupal Day Portugal 2020
 
Panels: Drupal Cubista
Panels: Drupal CubistaPanels: Drupal Cubista
Panels: Drupal Cubista
 
Como Colaborar na Tradução
Como Colaborar na Tradução Como Colaborar na Tradução
Como Colaborar na Tradução
 
Também há Drupal em Portugal
Também há Drupal em PortugalTambém há Drupal em Portugal
Também há Drupal em Portugal
 
Full Web Stack Security
Full Web Stack SecurityFull Web Stack Security
Full Web Stack Security
 
Rules e Drupal
Rules e DrupalRules e Drupal
Rules e Drupal
 
Temas em Drupal
Temas em DrupalTemas em Drupal
Temas em Drupal
 
Drupal e o seu ecossistema
Drupal e o seu ecossistemaDrupal e o seu ecossistema
Drupal e o seu ecossistema
 
Drupal mapping, a brid's eye view
Drupal mapping, a brid's eye viewDrupal mapping, a brid's eye view
Drupal mapping, a brid's eye view
 
Drupal 7
Drupal 7Drupal 7
Drupal 7
 
Business of Drupal
Business of DrupalBusiness of Drupal
Business of Drupal
 
DrupalCamp Lisboa 2011
DrupalCamp Lisboa 2011DrupalCamp Lisboa 2011
DrupalCamp Lisboa 2011
 
Business Angels e oportunidades de negócio
Business Angels e oportunidades de negócioBusiness Angels e oportunidades de negócio
Business Angels e oportunidades de negócio
 

Kürzlich hochgeladen

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Kürzlich hochgeladen (20)

Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 

DRUPAL CACHE SYSTEMS AND VARNISH

  • 1. Drupal Day 2020 – Drupal Cache Systems and Varnish Pedro Dias November 2020
  • 3. Internal Dynamic Page CacheInternal Page Caching 3 Every request constructs the output Saves the whole HTML for a given page, useful for a website with anonymous visitors Caches page components instead of the whole page, avoids a component to be computed in every requests if it behaves the same for all the pages Cache turned off Drupal out of the box caching systems
  • 4. 4 Drupal out of the box caching systems What is cacheable in Drupal? —Every renderable element
  • 5. Cache Max-ageCache Contexts 5 • A way of tagging a cacheable element used for bulk invalidation. • Used to create cache related elements • When a cache tag is invalidated, all elements with that tag are invalidated • Appliable to all renderable elements • Custom ones can be created • Provides a way of storing cache contextualized with the incoming request • Analogous to HTTP's Vary header. • Provides the ability for different users to see different cached content • Appliable to all renderable elements • Custom ones can be created • Instructs the time to live of the renderable element cache Cacheability Metadata in Drupal Cache Tags
  • 8. Enhance Drupal with Varnish 8 What is Varnish? - HTTP Accelerator known as HTTP Reverse Proxy - Stores the generated HTML for a given URL and serves the request without hitting the webserver - Speeds up delivery with a factor of 300 - 1000x
  • 9. Enhance Drupal with Varnish 9 Drupal and Varnish - Installing Drupal Varnish Cache Contrib module give the ability to integrate with Cache Tags. - Drupal + Varnish out-of-the-box work like Drupal Internal Page Cache - Same cache for every visitors Icons made by Freepick from www.flaticon.com
  • 10. Enhance Drupal with Varnish 10 Having Drupal + Varnish Installed Contextual response example • Our users have a attribute called “Has car” • We want to deliver different content to the user based on this attribute • Cache contexts won’t work
  • 11. Enhance Drupal with Varnish 11 Means that we cannot serve content based on the request context? • Out of the box no, Varnish caches pages based on the URL • Varnish offers a Vary mechanism to make cache be contextual for the request (Same logic as Drupal Cache-Contexts) • Varnish can be instructed by webserver response how the cache varies using the response Vary header • Vary header should contain which request headers should be used to store the cache based on their combinations • For our example we need to add the request header that contains the attribute value to make it vary
  • 12. Enhance Drupal with Varnish – Initial state 12 Icons made by Freepick from www.flaticon.com
  • 13. Enhance Drupal with Varnish – Adding the CDN 13 Icons made by Freepick from www.flaticon.com
  • 14. Enhance Drupal with Varnish – Make Info about car available on client-side 14 Icons made by Freepick from www.flaticon.com
  • 15. Enhance Drupal with Varnish – Add the cookie value as a Request header by CDN 15 Icons made by Freepick from www.flaticon.com
  • 16. Enhance Drupal with Varnish – Make cache Vary by X-Has-Car header 16 Icons made by Freepick from www.flaticon.com
  • 17. Enhance Drupal with Varnish - Summary 17 Summary • Value needed for cache to Vary passed to client side using a cookie • Leverage the use of a CDN to transform a cookie into a Request Header • Drupal instructs Varnish to Vary cache based on that header Icons made by Freepick from www.flaticon.com
  • 18. Enhance Drupal with Varnish – Combine with Cache contexts 18 Combine Varnish and Drupal cache • Cache contexts continue to make sense in reusable components • Enhances performance on shared components • Pages in which the content is different from the path should use the before explained mechanism
  • 19. Enhance Drupal with Varnish 19 Tips to handle cache problems • Remember that the first hit is always cached • Setup http.response.debug_cacheability_headers in services.yml and check X-Drupal-Cache-Contexts • For debugging Varnish you can pass all the request headers started to X to the response