SlideShare a Scribd company logo
Caching in Drupal
Presented by-
Vivek Panicker
Software Developer
Innoraft
Why do we need caching?
● To get faster response times
● To save server resources
● To save money
Quote
"There are only two hard things in Computer Science: cache
invalidation and naming things."
Drupal Cache storage
Cache backend
● This is the actual physical storage space for cache data.
● OOTB, Drupal stores cache data in the database.
● Drupal provides us with the option to configure different backends if required
for different types of caches (bins).
● For eg. the contrib module memcache provides the ability to use memcache
as the cache backend.
● OOTB, Drupal provides other backends in core like PhpBackend,
MemoryBackend, NullBackend, ChainedFastBackend of which
ChainedFastBackend is the most interesting as it helps us to combine two
cache backends (fast and slow) together.
Cache bin
● These are logical partitions of cached data.
● It is useful for
○ Logically segregating cache data based on type of cached content.
○ Faster retrieval of cached data - if the database is used as cache and all
cache data is stored in a single table, then time for retrieval of data would
increase with increase in the size of the table.
● OOTB, Drupal creates bins for storing bootstrap, config, container, render,
page, dynamic page etc caches and each of them has a separate database
table.
● Developers can easily provide a custom cache bin by just simply creating a
service definition.
Page level caching
● This is Drupal’s Built-in reverse proxy server.
● Stores the final prepared complete HTML response.
● This is used for anonymous user caching.
● A page cache entry gets invalidated as soon as any of it’s cache tags is
invalidated thus showing instantaneous page updates.
● Only the cache entries whose tags are invalidated are marked as invalid,
which is different from Drupal 7 where the entire page cache was invalidated.
● We can determine the cacheability metadata for a page by looking at the X-
Drupal-Cache-Tags and the X-Drupal-Cache-Contexts headers in the
response.
Page Cache
Dynamic Page Cache
● Page cache only caches for anonymous users.
● Dynamic page cache can cache for authenticated users.
● As authenticated users have a lot of personalized content, those parts of the
page which display those personalized content are replaced with
placeholders before being stored in the cache (a process called as auto-
placeholdering).
● When such a cached page is accessed, the cached data is fetched, the
placeholders are replaced with the actual content.
● As a result it is slower than page cache (which caches the complete
response) but still it makes accessing pages faster for authenticated users.
Source: https://wimleers.com/talk/rendering-caching-journey-layers
Cache API
Cache API
● Drupal allows developers to provide cacheability metadata for the cacheable
elements.
● This can be done mainly with the help of the following
○ Tags
○ Contexts
○ Max-age
Cache tags
● The data that we want to cache, is it aggregated from some other sources of
data like config, node?
● If yes, then we need to specify the data sources as dependencies, so that if
the data in any of the source changes, then our cached entity should be
marked as being stale i.e. invalid.
● The dependencies are specified in the form of cache tags.
● Cache tags are an array of strings mentioned as [‘thing:identifier’,
‘thing:identifier’, …..], where thing can be node/config/user/taxonomy_term
etc.
● There are also list cache tags, eg. node_list which gets invalidated when any
new node is added/removed.
Cache tags
● Eg. if the cached data depends on the data of node/5 and the system.site
configuration, then we have to specify the cache tags as [‘node:5’,
‘config:system.site’].
● Cache tags are invalidated across all cache bins.
● CDNs support using cache tags - eg. Fastly, CloudFlare, which is great!
● Varnish also supports cache tags.
● Contrib module like Purge can be used flush the reverse proxy servers/CDN.
Cache contexts
● The data that we want to cache, does it vary, i.e. have different
representations based on different factors?
● For eg. for different languages, the same data will have different translations.
● Since the data has different representations based on context, we have to
provide those contexts in the form of cache contexts.
● Cache Contexts are provided as an array of strings, eg: [‘language’, ‘url’] will be
the cache contexts for data varying by language OR URL.
● Each variation of the data is cached separately and is fetched based on the
context.
Cache Max-age
● The data that we want to cache, how long is it valid? Is there a fixed time?
● If yes, then we need to mention the time(in seconds) for it’s max-age.
● Usually this is not used for data that can be cached, since it usually is
invalidated by its cache tags.
● Max-age=0 , signifies that the data is not cacheable at all!
● At present there are some issues with max-age=0 being set for anonymous
user content, so we should use it with caution.
Bubbleability of Cache data
● Imagine a bottle of soda, where a bubble moves from the bottom to the top
and disrupts the surface of the soda.
● Similarly, cache metadata defined for the smallest render array of a page,
becomes part of the cache metadata of the entire page!
● Why?
○ Suppose there is a link in a page, which points to the current logged in user profile and
provides the user cache context in the render array..
○ When the entire page is cached, the system should know that it contains something that is
related to the current user.
So that when a different user views that page, the system does not end up showing the same
page from the cache which was shown to the previous user.
● Cache tags, contexts and max-age all bubble up to the page level cache.
Response headers
● In services.yml, we need to enable response headers debugging.
● After doing that, we start receiving X-Drupal-Cache-Tags and X-Drupal-Cache-
Contexts headers in the response.
● This contains the list of all the cache tags and cache contexts that the
response is dependant on.
● This is very useful for debugging cache related issues.
Additional points about Cache API
● Use with caution, as incorrect usage can cause potential security issue or
incorrect data being shown to the user!
Eg. not using user cache context on a block that shows the logged in user’s
name.
● Like all other awesome things in Drupal, Cache API provisions can be
extended for our custom usage.
● Eg. the contrib module memcache provides it own cache backend.
THANK YOU!!!

More Related Content

What's hot

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
 
Accra MongoDB User Group
Accra MongoDB User GroupAccra MongoDB User Group
Accra MongoDB User Group
MongoDB
 
MongoDB : Introduction
MongoDB : IntroductionMongoDB : Introduction
MongoDB : Introduction
Wildan Maulana
 
CouchDB: replicated data store for distributed proxy server
CouchDB: replicated data store for distributed proxy serverCouchDB: replicated data store for distributed proxy server
CouchDB: replicated data store for distributed proxy server
tkramar
 
Database , 17 Web
Database , 17 WebDatabase , 17 Web
Database , 17 Web
Ali Usman
 

What's hot (20)

Asp.net
Asp.netAsp.net
Asp.net
 
Microsoft azure database offerings
Microsoft azure database offeringsMicrosoft azure database offerings
Microsoft azure database offerings
 
Performance Optimization using Caching | Swatantra Kumar
Performance Optimization using Caching | Swatantra KumarPerformance Optimization using Caching | Swatantra Kumar
Performance Optimization using Caching | Swatantra Kumar
 
Accra MongoDB User Group
Accra MongoDB User GroupAccra MongoDB User Group
Accra MongoDB User Group
 
MongoDB : Introduction
MongoDB : IntroductionMongoDB : Introduction
MongoDB : Introduction
 
Mobile & Desktop Cache 2.0: How To Create A Scriptable Cache
Mobile & Desktop Cache 2.0: How To Create A Scriptable CacheMobile & Desktop Cache 2.0: How To Create A Scriptable Cache
Mobile & Desktop Cache 2.0: How To Create A Scriptable Cache
 
Caching
CachingCaching
Caching
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
 
CouchDB: replicated data store for distributed proxy server
CouchDB: replicated data store for distributed proxy serverCouchDB: replicated data store for distributed proxy server
CouchDB: replicated data store for distributed proxy server
 
How to use Cache scope
How to use Cache scopeHow to use Cache scope
How to use Cache scope
 
Couchbase
CouchbaseCouchbase
Couchbase
 
Intro to HBase
Intro to HBaseIntro to HBase
Intro to HBase
 
Postgresql tutorial
Postgresql tutorialPostgresql tutorial
Postgresql tutorial
 
Tempdb Not your average Database
Tempdb Not your average DatabaseTempdb Not your average Database
Tempdb Not your average Database
 
How to configure the cluster based on Multi-site (WAN) configuration
How to configure the clusterbased on Multi-site (WAN) configurationHow to configure the clusterbased on Multi-site (WAN) configuration
How to configure the cluster based on Multi-site (WAN) configuration
 
Hdfs internals
Hdfs internalsHdfs internals
Hdfs internals
 
Why no sql ? Why Couchbase ?
Why no sql ? Why Couchbase ?Why no sql ? Why Couchbase ?
Why no sql ? Why Couchbase ?
 
Database , 17 Web
Database , 17 WebDatabase , 17 Web
Database , 17 Web
 
NoSQL Databases
NoSQL DatabasesNoSQL Databases
NoSQL Databases
 
NOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQLNOSQL- Presentation on NoSQL
NOSQL- Presentation on NoSQL
 

Similar to Caching in drupal

Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
drupalcampest
 
Django book15 caching
Django book15 cachingDjango book15 caching
Django book15 caching
Shih-yi Wei
 
Drupal caching
Drupal cachingDrupal caching
Drupal caching
Exove
 
10 Cache Implementation
10  Cache Implementation10  Cache Implementation
10 Cache Implementation
Ranjan Kumar
 

Similar to Caching in drupal (20)

Don’t give up, You can... Cache!
Don’t give up, You can... Cache!Don’t give up, You can... Cache!
Don’t give up, You can... Cache!
 
Caching in Kentico 11
Caching in Kentico 11Caching in Kentico 11
Caching in Kentico 11
 
[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
 
Caching in Drupal 8
Caching in Drupal 8Caching in Drupal 8
Caching in Drupal 8
 
Scaling PHP apps
Scaling PHP appsScaling PHP apps
Scaling PHP apps
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
 
Distributed caching with java JCache
Distributed caching with java JCacheDistributed caching with java JCache
Distributed caching with java JCache
 
Артем Сильчук - 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
 
The Most Frequently Used Caching Headers
The Most Frequently Used Caching HeadersThe Most Frequently Used Caching Headers
The Most Frequently Used Caching Headers
 
Ror caching
Ror cachingRor caching
Ror caching
 
Django book15 caching
Django book15 cachingDjango book15 caching
Django book15 caching
 
Drupal caching
Drupal cachingDrupal caching
Drupal caching
 
Drupal 7 performance and optimization
Drupal 7 performance and optimizationDrupal 7 performance and optimization
Drupal 7 performance and optimization
 
Drupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case StudyDrupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case Study
 
Chapter 23
Chapter 23Chapter 23
Chapter 23
 
Drupal performance and scalability
Drupal performance and scalabilityDrupal performance and scalability
Drupal performance and scalability
 
Using oracle12c pluggable databases to archive
Using oracle12c pluggable databases to archiveUsing oracle12c pluggable databases to archive
Using oracle12c pluggable databases to archive
 
Tachyon meetup slides.
Tachyon meetup slides.Tachyon meetup slides.
Tachyon meetup slides.
 
10 Cache Implementation
10  Cache Implementation10  Cache Implementation
10 Cache Implementation
 

Recently uploaded

Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 

Recently uploaded (20)

Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 

Caching in drupal

  • 1. Caching in Drupal Presented by- Vivek Panicker Software Developer Innoraft
  • 2. Why do we need caching? ● To get faster response times ● To save server resources ● To save money
  • 3. Quote "There are only two hard things in Computer Science: cache invalidation and naming things."
  • 5. Cache backend ● This is the actual physical storage space for cache data. ● OOTB, Drupal stores cache data in the database. ● Drupal provides us with the option to configure different backends if required for different types of caches (bins). ● For eg. the contrib module memcache provides the ability to use memcache as the cache backend. ● OOTB, Drupal provides other backends in core like PhpBackend, MemoryBackend, NullBackend, ChainedFastBackend of which ChainedFastBackend is the most interesting as it helps us to combine two cache backends (fast and slow) together.
  • 6. Cache bin ● These are logical partitions of cached data. ● It is useful for ○ Logically segregating cache data based on type of cached content. ○ Faster retrieval of cached data - if the database is used as cache and all cache data is stored in a single table, then time for retrieval of data would increase with increase in the size of the table. ● OOTB, Drupal creates bins for storing bootstrap, config, container, render, page, dynamic page etc caches and each of them has a separate database table. ● Developers can easily provide a custom cache bin by just simply creating a service definition.
  • 8. ● This is Drupal’s Built-in reverse proxy server. ● Stores the final prepared complete HTML response. ● This is used for anonymous user caching. ● A page cache entry gets invalidated as soon as any of it’s cache tags is invalidated thus showing instantaneous page updates. ● Only the cache entries whose tags are invalidated are marked as invalid, which is different from Drupal 7 where the entire page cache was invalidated. ● We can determine the cacheability metadata for a page by looking at the X- Drupal-Cache-Tags and the X-Drupal-Cache-Contexts headers in the response. Page Cache
  • 9. Dynamic Page Cache ● Page cache only caches for anonymous users. ● Dynamic page cache can cache for authenticated users. ● As authenticated users have a lot of personalized content, those parts of the page which display those personalized content are replaced with placeholders before being stored in the cache (a process called as auto- placeholdering). ● When such a cached page is accessed, the cached data is fetched, the placeholders are replaced with the actual content. ● As a result it is slower than page cache (which caches the complete response) but still it makes accessing pages faster for authenticated users.
  • 12. Cache API ● Drupal allows developers to provide cacheability metadata for the cacheable elements. ● This can be done mainly with the help of the following ○ Tags ○ Contexts ○ Max-age
  • 13. Cache tags ● The data that we want to cache, is it aggregated from some other sources of data like config, node? ● If yes, then we need to specify the data sources as dependencies, so that if the data in any of the source changes, then our cached entity should be marked as being stale i.e. invalid. ● The dependencies are specified in the form of cache tags. ● Cache tags are an array of strings mentioned as [‘thing:identifier’, ‘thing:identifier’, …..], where thing can be node/config/user/taxonomy_term etc. ● There are also list cache tags, eg. node_list which gets invalidated when any new node is added/removed.
  • 14. Cache tags ● Eg. if the cached data depends on the data of node/5 and the system.site configuration, then we have to specify the cache tags as [‘node:5’, ‘config:system.site’]. ● Cache tags are invalidated across all cache bins. ● CDNs support using cache tags - eg. Fastly, CloudFlare, which is great! ● Varnish also supports cache tags. ● Contrib module like Purge can be used flush the reverse proxy servers/CDN.
  • 15. Cache contexts ● The data that we want to cache, does it vary, i.e. have different representations based on different factors? ● For eg. for different languages, the same data will have different translations. ● Since the data has different representations based on context, we have to provide those contexts in the form of cache contexts. ● Cache Contexts are provided as an array of strings, eg: [‘language’, ‘url’] will be the cache contexts for data varying by language OR URL. ● Each variation of the data is cached separately and is fetched based on the context.
  • 16. Cache Max-age ● The data that we want to cache, how long is it valid? Is there a fixed time? ● If yes, then we need to mention the time(in seconds) for it’s max-age. ● Usually this is not used for data that can be cached, since it usually is invalidated by its cache tags. ● Max-age=0 , signifies that the data is not cacheable at all! ● At present there are some issues with max-age=0 being set for anonymous user content, so we should use it with caution.
  • 17. Bubbleability of Cache data ● Imagine a bottle of soda, where a bubble moves from the bottom to the top and disrupts the surface of the soda. ● Similarly, cache metadata defined for the smallest render array of a page, becomes part of the cache metadata of the entire page! ● Why? ○ Suppose there is a link in a page, which points to the current logged in user profile and provides the user cache context in the render array.. ○ When the entire page is cached, the system should know that it contains something that is related to the current user. So that when a different user views that page, the system does not end up showing the same page from the cache which was shown to the previous user. ● Cache tags, contexts and max-age all bubble up to the page level cache.
  • 18. Response headers ● In services.yml, we need to enable response headers debugging. ● After doing that, we start receiving X-Drupal-Cache-Tags and X-Drupal-Cache- Contexts headers in the response. ● This contains the list of all the cache tags and cache contexts that the response is dependant on. ● This is very useful for debugging cache related issues.
  • 19. Additional points about Cache API ● Use with caution, as incorrect usage can cause potential security issue or incorrect data being shown to the user! Eg. not using user cache context on a block that shows the logged in user’s name. ● Like all other awesome things in Drupal, Cache API provisions can be extended for our custom usage. ● Eg. the contrib module memcache provides it own cache backend.