SlideShare una empresa de Scribd logo
1 de 22
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

Más contenido relacionado

La actualidad más candente

RESTful Web services in Drupal 8
RESTful Web services in Drupal 8RESTful Web services in Drupal 8
RESTful Web services in Drupal 8valuebound
 
Php & web server performace
Php & web server performacePhp & web server performace
Php & web server performaceTuyển Đoàn
 
Understanding Web Cache
Understanding Web CacheUnderstanding Web Cache
Understanding Web CacheProdigyView
 
World Wide Web Caching
World Wide Web CachingWorld Wide Web Caching
World Wide Web Cachingersanbilik
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sitesdrupalcampest
 
Drupal caching
Drupal cachingDrupal caching
Drupal cachingExove
 
Performance Optimization using Caching | Swatantra Kumar
Performance Optimization using Caching | Swatantra KumarPerformance Optimization using Caching | Swatantra Kumar
Performance Optimization using Caching | Swatantra KumarSwatantra Kumar
 
Sofia WP User Group Presentation
Sofia WP User Group PresentationSofia WP User Group Presentation
Sofia WP User Group PresentationDaniel Kanchev
 
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 TeamMydbops
 
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 wheelLEDC 2016
 
Caching with Ruby
Caching with RubyCaching with Ruby
Caching with RubyLuong Vo
 
Cloud Hosting Services
Cloud Hosting ServicesCloud Hosting Services
Cloud Hosting ServicesHTS Hosting
 
Postgres connections at scale
Postgres connections at scalePostgres connections at scale
Postgres connections at scaleMydbops
 

La actualidad más candente (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 a 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 HeadersHTS Hosting
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cacheMarc 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 SolutionsITviec
 
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 PlusKevin Jones
 
Basic Caching Terminology
Basic Caching TerminologyBasic Caching Terminology
Basic Caching TerminologyHTS Hosting
 
Http Caching for the Android Aficionado
Http Caching for the Android AficionadoHttp Caching for the Android Aficionado
Http Caching for the Android AficionadoPaul Blundell
 
Web Site Optimization
Web Site OptimizationWeb Site Optimization
Web Site OptimizationSunil Patil
 
Web site optimization
Web site optimizationWeb site optimization
Web site optimizationSunil Patil
 
Academy PRO: HTML5 Data storage
Academy PRO: HTML5 Data storageAcademy PRO: HTML5 Data storage
Academy PRO: HTML5 Data storageBinary Studio
 
Cdn technology overview
Cdn technology overviewCdn technology overview
Cdn technology overviewYoohyun Kim
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesExove
 

Similar a 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
 

Más de valuebound

Scaling Drupal for High Traffic Websites
Scaling Drupal for High Traffic WebsitesScaling Drupal for High Traffic Websites
Scaling Drupal for High Traffic Websitesvaluebound
 
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).pdfvaluebound
 
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 Appsvaluebound
 
Mastering Drupal Theming
Mastering Drupal ThemingMastering Drupal Theming
Mastering Drupal Themingvaluebound
 
The Benefits of Cloud Engineering
The Benefits of Cloud EngineeringThe Benefits of Cloud Engineering
The Benefits of Cloud Engineeringvaluebound
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computingvaluebound
 
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 ChatGPTvaluebound
 
Content Creation Solution | Valuebound
Content Creation Solution | ValueboundContent Creation Solution | Valuebound
Content Creation Solution | Valueboundvaluebound
 
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 projectsvaluebound
 
Chatbot with RASA | Valuebound
Chatbot with RASA | ValueboundChatbot with RASA | Valuebound
Chatbot with RASA | Valueboundvaluebound
 
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 | Valueboundvaluebound
 
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 browservaluebound
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDBvaluebound
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 
Dependency Injection in Drupal 8
Dependency Injection in Drupal 8Dependency Injection in Drupal 8
Dependency Injection in Drupal 8valuebound
 

Más de 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
 

Último

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Último (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

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.