SlideShare a Scribd company logo
Drupal 8 Caching
Subhash Yadav
https://www.drupal.org/u/subhashuyadav
A cache is a stored copy of a resource so future requests for that
resource can be served faster.
The data stored in a cache might be the result of an earlier
computation, or the duplicate of data stored elsewhere.
Caches are found at every level of a content's journey from the
original server to the browser.
What is cache?
Why Caching?
● Faster than recomputing a result or reading from a slower
data store; thus the, more requests can be served from the
cache, the faster the system performs i.e. maximum output
with minimum latency.
● Eases the load of the server
● Improves responsiveness
HTTP Headers
HTTP Headers is where caching information is exchanged between the origin
server and cdn, proxies including varnish all the way to the browser.
Example : HTTP/1.x 200 OK
Transfer-Encoding: chunked
Date: Fri, 27 Nov 2017 04:36:25 GMT
Server: LiteSpeed
Connection: close
X-Powered-By: W3 Total Cache/0.8
Expires: Fri, 27 Nov 2017 05:36:25 GMT
Etag: "pub1259380237;gz"
Cache-Control: max-age=3600, public
Content-Type: text/html; charset=UTF-8
Last-Modified: Sat, 28 Nov 2009 03:50:37 GMT
Content-Encoding: gzip
Vary: Accept-Encoding, Cookie, User-Agent
The Expires header sets a time in the future
when the content will expire. This header is
probably best used only as a fall back.
Expires
A unique hash identifier of the cacheable object that the browser
caches.
Whenever a cached response is requested again, browser checks
with server if the eTag of the response is modified. If response is
not modified server returns 304 not modified else 200 along
with new response & new eTag.
Etag
The date-time this cacheable object was last cached.
(Similar to eTag)
Last-modified
When a cache receives a request that can be satisfied by a
cached response that has a Vary header field, it must not use
that cached response unless all header fields as nominated
by the Vary header match in both the original (cached)
request and the new request.
This can be useful for serving content dynamically.
Vary
Each resource can define its caching policy via the
Cache-Control HTTP header.
Cache-Control directives control who can cache the
response, under which conditions, and for how long.
Cache-Control
no-cache: Indicates that the returned response can't be used to satisfy a
subsequent request to the same URL without first checking with the
server if the response has changed.
no-store: It simply disallows the browser and all intermediate caches
from
storing any version of the returned response.
public / private: If the response is marked as "public", then it can be cached, even
if
it has HTTP authentication associated with it, and even when the
response status code isn't normally cacheable.
private marked responses are typically intended for
a single user, so
an intermediate cache is not allowed to cache them but browser can
cache them.
Cache-Control Directives
max-age : Configures the maximum age that the content may be cached
before
it must revalidate or re-download the content from the origin server.
This replaces the Expires header for modern browsing.
This option takes its value in seconds with a maximum valid
freshness time of one year (31536000 seconds).
s-maxage : This is very similar to the max-age setting, in that it indicates the
amount of time that the content can be cached.
The difference is that this option is applied only to intermediary
caches.
Cache-Control Directives
All things that either are directly renderable or are used to determine
what to render provide cacheability metadata.
Cacheability metadata consists of three properties:
cache tags : For dependencies on data managed by
Drupal, like
entities & configuration.
cache contexts : For variations, i.e. dependencies on the request
context.
cache max-age : For time-sensitive caching, i.e. time dependencies
Cacheability metadata
Cache tags provide a declarative way to track which cache items
depend on some data managed by Drupal.
The role of the tags is to identify cache items across multiple bins for
proper invalidation.
In a typical scenario, a user may have modified a node that appears in
two views, three blocks, and on twelve pages. Without cache tags, we
couldn't know which cache items to invalidate. So we'd have to
invalidate everything and sacrifice effectiveness to achieve
correctness. With cache tags we can have both.
Cache Tags
Syntax: “Thing:identifier”
Example: node:5 -- cache tag for node entity 5
user:4 -- cache tag for user entity 4
node_list -- list cache tag for node
$tags = array('node:1', 'user:7');
Drupal::cache()->set($cid, $data,
CacheBackendInterface::CACHE_PERMANENT, $tags);
// Invalidate all cache items with certain tags.
DrupalCoreCacheCache::invalidateTags($tags);
Cache Tags
● Cache contexts provide a declarative way to create context-
dependent variations of something that needs to be cached.
● Determines how to vary items according to request.
● Similar to D7 block constants like DRUPAL_NO_CACHE /
DRUPAL_CACHE_PER_ROLE / DRUPAL_CACHE_PER_PAGE,
but with many more options.
● Cache contexts are hierarchical in nature.
Cache Contexts
Example : theme -- vary by negotiated theme.
user.roles -- vary by the combination of
roles
$variables['#cache']['contexts'][] = 'url.path';
Cache Contexts
Cache max-age
● Cache max-age provides a declarative way to create time-
dependent caches.
● Controls how long an item may be cached by number of seconds.
● 0 means cacheable for zero seconds, i.e. not cacheable
● DrupalCoreCacheCache::PERMANENT means cacheable
forever, i.e. this will only ever be invalidated due to cache tags.
(In other words: ∞, or infinite seconds)
● Varnish is just a web-server in front of origin webserver.
● Also known as a caching HTTP reverse proxy.
● It can be used with cache tags to make cache invalidation easy.
● Every request to the origin web-server goes through varnish.
● If varnish doesn’t have a request cached, the request is passed to
the backend. Upon response, varnish reads the response
headers and if response is cacheable varnish caches the
response for next similar requests.
Varnish cache
● Varnish will only cache resources that are requested through an
idempotent HTTP verb, which are the verbs that do not change
the state of the resources.
● HTTP verbs that Varnish can handle: GET, HEAD
● PUT, POST, DELETE, TRACE, OPTIONS cannot be cached by
the varnish.
● Varnish default cache setting is 120 sec (2 min).
Varnish cache
You need to do three things to make sure Varnish works well with the
cache tags generated by Drupal:
● Update your Varnish VCL so it handles BAN requests properly.
Location : /etc/default/varnish/default.vcl
http://foshttpcache.readthedocs.io/en/stable/varnish-
configuration.html#tagging
Varnish cache
Varnish cache
● Send a cache tags header:
Drupal's Purge module automatically configures
Purge-Cache-Tags headers.
● Send a BAN request when content or configuration changes:
Add an HTTP Purger using Generic HTTP Purger module.
Configure a cron job to process the Purge queue.
Thank you

More Related Content

What's hot

Presentation1
Presentation1Presentation1
Presentation1
Rosie brown
 
RESTful Web services in Drupal 8
RESTful Web services in Drupal 8RESTful Web services in Drupal 8
RESTful Web services in Drupal 8
valuebound
 
Php & web server performace
Php & web server performacePhp & web server performace
Php & web server performace
Tuyển Đoàn
 
Understanding Web Cache
Understanding Web CacheUnderstanding Web Cache
Understanding Web Cache
ProdigyView
 
World Wide Web Caching
World Wide Web CachingWorld Wide Web Caching
World Wide Web Caching
ersanbilik
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
drupalcampest
 
Drupal caching
Drupal cachingDrupal caching
Drupal caching
Exove
 
Performance Optimization using Caching | Swatantra Kumar
Performance Optimization using Caching | Swatantra KumarPerformance Optimization using Caching | Swatantra Kumar
Performance Optimization using Caching | Swatantra Kumar
Swatantra Kumar
 
Caching Strategies
Caching StrategiesCaching Strategies
Caching Strategies
Michal Špaček
 
23 Ways To Speed Up WordPress
23 Ways To Speed Up WordPress23 Ways To Speed Up WordPress
23 Ways To Speed Up WordPress
Zero Point Development
 
Sofia WP User Group Presentation
Sofia WP User Group PresentationSofia WP User Group Presentation
Sofia WP User Group Presentation
Daniel Kanchev
 
Optimize
OptimizeOptimize
Insight on MongoDB Change Stream - Abhishek.D, Mydbops Team
Insight on MongoDB Change Stream - Abhishek.D, Mydbops TeamInsight on MongoDB Change Stream - Abhishek.D, Mydbops Team
Insight on MongoDB Change Stream - Abhishek.D, Mydbops Team
Mydbops
 
Mini-Training: To cache or not to cache
Mini-Training: To cache or not to cacheMini-Training: To cache or not to cache
Mini-Training: To cache or not to cache
Betclic Everest Group Tech Team
 
Memcached: What is it and what does it do? (PHP Version)
Memcached: What is it and what does it do? (PHP Version)Memcached: What is it and what does it do? (PHP Version)
Memcached: What is it and what does it do? (PHP Version)
Brian Moon
 
Memcached: What is it and what does it do?
Memcached: What is it and what does it do?Memcached: What is it and what does it do?
Memcached: What is it and what does it do?
Brian Moon
 
Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel
Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheelАртем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel
Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel
LEDC 2016
 
Caching with Ruby
Caching with RubyCaching with Ruby
Caching with Ruby
Luong Vo
 
Cloud Hosting Services
Cloud Hosting ServicesCloud Hosting Services
Cloud Hosting Services
HTS Hosting
 
Postgres connections at scale
Postgres connections at scalePostgres connections at scale
Postgres connections at scale
Mydbops
 

What's hot (20)

Presentation1
Presentation1Presentation1
Presentation1
 
RESTful Web services in Drupal 8
RESTful Web services in Drupal 8RESTful Web services in Drupal 8
RESTful Web services in Drupal 8
 
Php & web server performace
Php & web server performacePhp & web server performace
Php & web server performace
 
Understanding Web Cache
Understanding Web CacheUnderstanding Web Cache
Understanding Web Cache
 
World Wide Web Caching
World Wide Web CachingWorld Wide Web Caching
World Wide Web Caching
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
 
Drupal caching
Drupal cachingDrupal caching
Drupal caching
 
Performance Optimization using Caching | Swatantra Kumar
Performance Optimization using Caching | Swatantra KumarPerformance Optimization using Caching | Swatantra Kumar
Performance Optimization using Caching | Swatantra Kumar
 
Caching Strategies
Caching StrategiesCaching Strategies
Caching Strategies
 
23 Ways To Speed Up WordPress
23 Ways To Speed Up WordPress23 Ways To Speed Up WordPress
23 Ways To Speed Up WordPress
 
Sofia WP User Group Presentation
Sofia WP User Group PresentationSofia WP User Group Presentation
Sofia WP User Group Presentation
 
Optimize
OptimizeOptimize
Optimize
 
Insight on MongoDB Change Stream - Abhishek.D, Mydbops Team
Insight on MongoDB Change Stream - Abhishek.D, Mydbops TeamInsight on MongoDB Change Stream - Abhishek.D, Mydbops Team
Insight on MongoDB Change Stream - Abhishek.D, Mydbops Team
 
Mini-Training: To cache or not to cache
Mini-Training: To cache or not to cacheMini-Training: To cache or not to cache
Mini-Training: To cache or not to cache
 
Memcached: What is it and what does it do? (PHP Version)
Memcached: What is it and what does it do? (PHP Version)Memcached: What is it and what does it do? (PHP Version)
Memcached: What is it and what does it do? (PHP Version)
 
Memcached: What is it and what does it do?
Memcached: What is it and what does it do?Memcached: What is it and what does it do?
Memcached: What is it and what does it do?
 
Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel
Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheelАртем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel
Артем Сильчук - Respond in 60ms. Extremal optimization with reinventing a wheel
 
Caching with Ruby
Caching with RubyCaching with Ruby
Caching with Ruby
 
Cloud Hosting Services
Cloud Hosting ServicesCloud Hosting Services
Cloud Hosting Services
 
Postgres connections at scale
Postgres connections at scalePostgres connections at scale
Postgres connections at scale
 

Similar to Caching in Drupal 8

The Most Frequently Used Caching Headers
The Most Frequently Used Caching HeadersThe Most Frequently Used Caching Headers
The Most Frequently Used Caching Headers
HTS Hosting
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
Marc Cortinas Val
 
[Hanoi-August 13] Tech Talk on Caching Solutions
[Hanoi-August 13] Tech Talk on Caching Solutions[Hanoi-August 13] Tech Talk on Caching Solutions
[Hanoi-August 13] Tech Talk on Caching Solutions
ITviec
 
Varnish –Http Accelerator
Varnish –Http AcceleratorVarnish –Http Accelerator
Varnish –Http Accelerator
Smruti Ranjan Tripathy
 
Content Caching with NGINX and NGINX Plus
Content Caching with NGINX and NGINX PlusContent Caching with NGINX and NGINX Plus
Content Caching with NGINX and NGINX Plus
Kevin Jones
 
Browser Caching
Browser CachingBrowser Caching
Browser Caching
Jaiswal Siddharth
 
Ror caching
Ror cachingRor caching
Ror caching
Kashyap Parmar
 
Basic Caching Terminology
Basic Caching TerminologyBasic Caching Terminology
Basic Caching Terminology
HTS Hosting
 
Caching on the web
Caching on the webCaching on the web
Caching on the web
Jean Carlo Emer
 
Http caching
Http cachingHttp caching
Http caching
Samsarabbi
 
Http Caching for the Android Aficionado
Http Caching for the Android AficionadoHttp Caching for the Android Aficionado
Http Caching for the Android Aficionado
Paul Blundell
 
Web Site Optimization
Web Site OptimizationWeb Site Optimization
Web Site Optimization
Sunil Patil
 
Web site optimization
Web site optimizationWeb site optimization
Web site optimization
Sunil Patil
 
Caching
CachingCaching
Caching
saravanan_k83
 
Nginx dhruba mandal
Nginx dhruba mandalNginx dhruba mandal
Nginx dhruba mandal
Dhrubaji Mandal ♛
 
Caching in drupal
Caching in drupalCaching in drupal
Caching in drupal
Vivek Panicker
 
Academy PRO: HTML5 Data storage
Academy PRO: HTML5 Data storageAcademy PRO: HTML5 Data storage
Academy PRO: HTML5 Data storage
Binary Studio
 
Nginx
NginxNginx
Cdn technology overview
Cdn technology overviewCdn technology overview
Cdn technology overview
Yoohyun Kim
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
Exove
 

Similar to Caching in Drupal 8 (20)

The Most Frequently Used Caching Headers
The Most Frequently Used Caching HeadersThe Most Frequently Used Caching Headers
The Most Frequently Used Caching Headers
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
 
[Hanoi-August 13] Tech Talk on Caching Solutions
[Hanoi-August 13] Tech Talk on Caching Solutions[Hanoi-August 13] Tech Talk on Caching Solutions
[Hanoi-August 13] Tech Talk on Caching Solutions
 
Varnish –Http Accelerator
Varnish –Http AcceleratorVarnish –Http Accelerator
Varnish –Http Accelerator
 
Content Caching with NGINX and NGINX Plus
Content Caching with NGINX and NGINX PlusContent Caching with NGINX and NGINX Plus
Content Caching with NGINX and NGINX Plus
 
Browser Caching
Browser CachingBrowser Caching
Browser Caching
 
Ror caching
Ror cachingRor caching
Ror caching
 
Basic Caching Terminology
Basic Caching TerminologyBasic Caching Terminology
Basic Caching Terminology
 
Caching on the web
Caching on the webCaching on the web
Caching on the web
 
Http caching
Http cachingHttp caching
Http caching
 
Http Caching for the Android Aficionado
Http Caching for the Android AficionadoHttp Caching for the Android Aficionado
Http Caching for the Android Aficionado
 
Web Site Optimization
Web Site OptimizationWeb Site Optimization
Web Site Optimization
 
Web site optimization
Web site optimizationWeb site optimization
Web site optimization
 
Caching
CachingCaching
Caching
 
Nginx dhruba mandal
Nginx dhruba mandalNginx dhruba mandal
Nginx dhruba mandal
 
Caching in drupal
Caching in drupalCaching in drupal
Caching in drupal
 
Academy PRO: HTML5 Data storage
Academy PRO: HTML5 Data storageAcademy PRO: HTML5 Data storage
Academy PRO: HTML5 Data storage
 
Nginx
NginxNginx
Nginx
 
Cdn technology overview
Cdn technology overviewCdn technology overview
Cdn technology overview
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
 

More from valuebound

Scaling Drupal for High Traffic Websites
Scaling Drupal for High Traffic WebsitesScaling Drupal for High Traffic Websites
Scaling Drupal for High Traffic Websites
valuebound
 
Drupal 7 to Drupal 10 Migration A Fintech Strategic Blueprint (1).pdf
Drupal 7 to Drupal 10 Migration A Fintech Strategic Blueprint (1).pdfDrupal 7 to Drupal 10 Migration A Fintech Strategic Blueprint (1).pdf
Drupal 7 to Drupal 10 Migration A Fintech Strategic Blueprint (1).pdf
valuebound
 
How to Use DDEV to Streamline Your Drupal Development Process.
How to Use DDEV to Streamline Your Drupal Development Process.How to Use DDEV to Streamline Your Drupal Development Process.
How to Use DDEV to Streamline Your Drupal Development Process.
valuebound
 
How to Use AWS to Automate Your IT Operation| Valuebound
How to Use AWS to Automate Your IT Operation| Valuebound How to Use AWS to Automate Your IT Operation| Valuebound
How to Use AWS to Automate Your IT Operation| Valuebound
valuebound
 
How to Use Firebase to Send Push Notifications to React Native and Node.js Apps
How to Use Firebase to Send Push Notifications to React Native and Node.js AppsHow to Use Firebase to Send Push Notifications to React Native and Node.js Apps
How to Use Firebase to Send Push Notifications to React Native and Node.js Apps
valuebound
 
Mastering Drupal Theming
Mastering Drupal ThemingMastering Drupal Theming
Mastering Drupal Theming
valuebound
 
The Benefits of Cloud Engineering
The Benefits of Cloud EngineeringThe Benefits of Cloud Engineering
The Benefits of Cloud Engineering
valuebound
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computing
valuebound
 
The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...
The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...
The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...
valuebound
 
Deep dive into ChatGPT
Deep dive into ChatGPTDeep dive into ChatGPT
Deep dive into ChatGPT
valuebound
 
Content Creation Solution | Valuebound
Content Creation Solution | ValueboundContent Creation Solution | Valuebound
Content Creation Solution | Valuebound
valuebound
 
Road ahead for Drupal 8 contributed projects
Road ahead for Drupal 8 contributed projectsRoad ahead for Drupal 8 contributed projects
Road ahead for Drupal 8 contributed projects
valuebound
 
Chatbot with RASA | Valuebound
Chatbot with RASA | ValueboundChatbot with RASA | Valuebound
Chatbot with RASA | Valuebound
valuebound
 
Drupal and Artificial Intelligence for Personalization
Drupal and Artificial Intelligence for Personalization Drupal and Artificial Intelligence for Personalization
Drupal and Artificial Intelligence for Personalization
valuebound
 
Drupal growth in last year | Valuebound
Drupal growth in last year | ValueboundDrupal growth in last year | Valuebound
Drupal growth in last year | Valuebound
valuebound
 
BE NEW TO THE WORLD "BRAVE FROM CHROME"
BE NEW TO THE WORLD "BRAVE FROM CHROME"BE NEW TO THE WORLD "BRAVE FROM CHROME"
BE NEW TO THE WORLD "BRAVE FROM CHROME"
valuebound
 
Event loop in browser
Event loop in browserEvent loop in browser
Event loop in browser
valuebound
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
valuebound
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
valuebound
 
Dependency Injection in Drupal 8
Dependency Injection in Drupal 8Dependency Injection in Drupal 8
Dependency Injection in Drupal 8
valuebound
 

More from valuebound (20)

Scaling Drupal for High Traffic Websites
Scaling Drupal for High Traffic WebsitesScaling Drupal for High Traffic Websites
Scaling Drupal for High Traffic Websites
 
Drupal 7 to Drupal 10 Migration A Fintech Strategic Blueprint (1).pdf
Drupal 7 to Drupal 10 Migration A Fintech Strategic Blueprint (1).pdfDrupal 7 to Drupal 10 Migration A Fintech Strategic Blueprint (1).pdf
Drupal 7 to Drupal 10 Migration A Fintech Strategic Blueprint (1).pdf
 
How to Use DDEV to Streamline Your Drupal Development Process.
How to Use DDEV to Streamline Your Drupal Development Process.How to Use DDEV to Streamline Your Drupal Development Process.
How to Use DDEV to Streamline Your Drupal Development Process.
 
How to Use AWS to Automate Your IT Operation| Valuebound
How to Use AWS to Automate Your IT Operation| Valuebound How to Use AWS to Automate Your IT Operation| Valuebound
How to Use AWS to Automate Your IT Operation| Valuebound
 
How to Use Firebase to Send Push Notifications to React Native and Node.js Apps
How to Use Firebase to Send Push Notifications to React Native and Node.js AppsHow to Use Firebase to Send Push Notifications to React Native and Node.js Apps
How to Use Firebase to Send Push Notifications to React Native and Node.js Apps
 
Mastering Drupal Theming
Mastering Drupal ThemingMastering Drupal Theming
Mastering Drupal Theming
 
The Benefits of Cloud Engineering
The Benefits of Cloud EngineeringThe Benefits of Cloud Engineering
The Benefits of Cloud Engineering
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computing
 
The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...
The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...
The Future of Cloud Engineering: Emerging Trends and Technologies to Watch in...
 
Deep dive into ChatGPT
Deep dive into ChatGPTDeep dive into ChatGPT
Deep dive into ChatGPT
 
Content Creation Solution | Valuebound
Content Creation Solution | ValueboundContent Creation Solution | Valuebound
Content Creation Solution | Valuebound
 
Road ahead for Drupal 8 contributed projects
Road ahead for Drupal 8 contributed projectsRoad ahead for Drupal 8 contributed projects
Road ahead for Drupal 8 contributed projects
 
Chatbot with RASA | Valuebound
Chatbot with RASA | ValueboundChatbot with RASA | Valuebound
Chatbot with RASA | Valuebound
 
Drupal and Artificial Intelligence for Personalization
Drupal and Artificial Intelligence for Personalization Drupal and Artificial Intelligence for Personalization
Drupal and Artificial Intelligence for Personalization
 
Drupal growth in last year | Valuebound
Drupal growth in last year | ValueboundDrupal growth in last year | Valuebound
Drupal growth in last year | Valuebound
 
BE NEW TO THE WORLD "BRAVE FROM CHROME"
BE NEW TO THE WORLD "BRAVE FROM CHROME"BE NEW TO THE WORLD "BRAVE FROM CHROME"
BE NEW TO THE WORLD "BRAVE FROM CHROME"
 
Event loop in browser
Event loop in browserEvent loop in browser
Event loop in browser
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
Dependency Injection in Drupal 8
Dependency Injection in Drupal 8Dependency Injection in Drupal 8
Dependency Injection in Drupal 8
 

Recently uploaded

Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 

Recently uploaded (20)

Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 

Caching in Drupal 8

  • 1. Drupal 8 Caching Subhash Yadav https://www.drupal.org/u/subhashuyadav
  • 2. A cache is a stored copy of a resource so future requests for that resource can be served faster. The data stored in a cache might be the result of an earlier computation, or the duplicate of data stored elsewhere. Caches are found at every level of a content's journey from the original server to the browser. What is cache?
  • 3. Why Caching? ● Faster than recomputing a result or reading from a slower data store; thus the, more requests can be served from the cache, the faster the system performs i.e. maximum output with minimum latency. ● Eases the load of the server ● Improves responsiveness
  • 4. HTTP Headers HTTP Headers is where caching information is exchanged between the origin server and cdn, proxies including varnish all the way to the browser. Example : HTTP/1.x 200 OK Transfer-Encoding: chunked Date: Fri, 27 Nov 2017 04:36:25 GMT Server: LiteSpeed Connection: close X-Powered-By: W3 Total Cache/0.8 Expires: Fri, 27 Nov 2017 05:36:25 GMT Etag: "pub1259380237;gz" Cache-Control: max-age=3600, public Content-Type: text/html; charset=UTF-8 Last-Modified: Sat, 28 Nov 2009 03:50:37 GMT Content-Encoding: gzip Vary: Accept-Encoding, Cookie, User-Agent
  • 5. The Expires header sets a time in the future when the content will expire. This header is probably best used only as a fall back. Expires
  • 6. A unique hash identifier of the cacheable object that the browser caches. Whenever a cached response is requested again, browser checks with server if the eTag of the response is modified. If response is not modified server returns 304 not modified else 200 along with new response & new eTag. Etag
  • 7. The date-time this cacheable object was last cached. (Similar to eTag) Last-modified
  • 8. When a cache receives a request that can be satisfied by a cached response that has a Vary header field, it must not use that cached response unless all header fields as nominated by the Vary header match in both the original (cached) request and the new request. This can be useful for serving content dynamically. Vary
  • 9. Each resource can define its caching policy via the Cache-Control HTTP header. Cache-Control directives control who can cache the response, under which conditions, and for how long. Cache-Control
  • 10. no-cache: Indicates that the returned response can't be used to satisfy a subsequent request to the same URL without first checking with the server if the response has changed. no-store: It simply disallows the browser and all intermediate caches from storing any version of the returned response. public / private: If the response is marked as "public", then it can be cached, even if it has HTTP authentication associated with it, and even when the response status code isn't normally cacheable. private marked responses are typically intended for a single user, so an intermediate cache is not allowed to cache them but browser can cache them. Cache-Control Directives
  • 11. max-age : Configures the maximum age that the content may be cached before it must revalidate or re-download the content from the origin server. This replaces the Expires header for modern browsing. This option takes its value in seconds with a maximum valid freshness time of one year (31536000 seconds). s-maxage : This is very similar to the max-age setting, in that it indicates the amount of time that the content can be cached. The difference is that this option is applied only to intermediary caches. Cache-Control Directives
  • 12. All things that either are directly renderable or are used to determine what to render provide cacheability metadata. Cacheability metadata consists of three properties: cache tags : For dependencies on data managed by Drupal, like entities & configuration. cache contexts : For variations, i.e. dependencies on the request context. cache max-age : For time-sensitive caching, i.e. time dependencies Cacheability metadata
  • 13. Cache tags provide a declarative way to track which cache items depend on some data managed by Drupal. The role of the tags is to identify cache items across multiple bins for proper invalidation. In a typical scenario, a user may have modified a node that appears in two views, three blocks, and on twelve pages. Without cache tags, we couldn't know which cache items to invalidate. So we'd have to invalidate everything and sacrifice effectiveness to achieve correctness. With cache tags we can have both. Cache Tags
  • 14. Syntax: “Thing:identifier” Example: node:5 -- cache tag for node entity 5 user:4 -- cache tag for user entity 4 node_list -- list cache tag for node $tags = array('node:1', 'user:7'); Drupal::cache()->set($cid, $data, CacheBackendInterface::CACHE_PERMANENT, $tags); // Invalidate all cache items with certain tags. DrupalCoreCacheCache::invalidateTags($tags); Cache Tags
  • 15. ● Cache contexts provide a declarative way to create context- dependent variations of something that needs to be cached. ● Determines how to vary items according to request. ● Similar to D7 block constants like DRUPAL_NO_CACHE / DRUPAL_CACHE_PER_ROLE / DRUPAL_CACHE_PER_PAGE, but with many more options. ● Cache contexts are hierarchical in nature. Cache Contexts
  • 16. Example : theme -- vary by negotiated theme. user.roles -- vary by the combination of roles $variables['#cache']['contexts'][] = 'url.path'; Cache Contexts
  • 17. Cache max-age ● Cache max-age provides a declarative way to create time- dependent caches. ● Controls how long an item may be cached by number of seconds. ● 0 means cacheable for zero seconds, i.e. not cacheable ● DrupalCoreCacheCache::PERMANENT means cacheable forever, i.e. this will only ever be invalidated due to cache tags. (In other words: ∞, or infinite seconds)
  • 18. ● Varnish is just a web-server in front of origin webserver. ● Also known as a caching HTTP reverse proxy. ● It can be used with cache tags to make cache invalidation easy. ● Every request to the origin web-server goes through varnish. ● If varnish doesn’t have a request cached, the request is passed to the backend. Upon response, varnish reads the response headers and if response is cacheable varnish caches the response for next similar requests. Varnish cache
  • 19. ● Varnish will only cache resources that are requested through an idempotent HTTP verb, which are the verbs that do not change the state of the resources. ● HTTP verbs that Varnish can handle: GET, HEAD ● PUT, POST, DELETE, TRACE, OPTIONS cannot be cached by the varnish. ● Varnish default cache setting is 120 sec (2 min). Varnish cache
  • 20. You need to do three things to make sure Varnish works well with the cache tags generated by Drupal: ● Update your Varnish VCL so it handles BAN requests properly. Location : /etc/default/varnish/default.vcl http://foshttpcache.readthedocs.io/en/stable/varnish- configuration.html#tagging Varnish cache
  • 21. Varnish cache ● Send a cache tags header: Drupal's Purge module automatically configures Purge-Cache-Tags headers. ● Send a BAN request when content or configuration changes: Add an HTTP Purger using Generic HTTP Purger module. Configure a cron job to process the Purge queue.