SlideShare une entreprise Scribd logo
1  sur  19
Caching in
WordPress
David Biňovec
david_binovec@parade.com
Presentation outline
● What cache is, what to cache
● Caching options in PHP and MySQL
o Memcached, Alternative PHP Cache (APC)
o MySQL Query Cache
● Page level a Object Cache
● Is WordPress cache-ready?
o Transients API
o WP_Object_Cache a wp_cache funkce
o oEmbed cache
What is a cache and what to cache?
● transparently stored data so that future requests for that
data can be served faster
● You can cache almost everything
o whole pages, objects
o external API requests, resource demanding
operations ...
● … and even more
o MySQL Query Cache
o OpCode
MySQL Query Cache
● only identical and deterministic SELECT
requests
● inter session persistent
● cache flushing after the change of relevant
data
● non-distributed
Cache engines
● Memcached
o distributed (server accessible via telnet)
o key-value pairs saved in a memory
o PECL extension for PHP (memcached / memcache)
● Alternative PHP Cache (APC)
o Opcode and user cache (PHP <= 5.4), APCu (PHP 5.5)
o non-distributed
● Flat file
o eg. mod_rewrite (WP Super Cache), CDN
Page Level vs. Object Cache
● Page level cache (e.g. WP Super Cache)
o saves only whole pages
o every single page has to be generated on it’s own
with all database requests, API call etc..
o usually is not available for non logged in users
● Object cache (APC, Memcached, W3TC)
o reusable for a generation of multiple pages
o works also for logged in users
o has affect even on WordPress administration
Page Level Cache
● HTML files saved on hard drive
o loading via PHP or mod_rewrite (WP Super Cache)
● memcached (Batcache)
o can be used even without PHP (NginX, Apache ...)
● CDN
o cloudflare (W3TC)
o anything else (WP Super Cache)
How to cache a page in WordPress
WP Super Cache - mod_rewrite
Object Cache
● reusable objects
o either in terms of a single requests
o or, and with better performance, in multiple requests
● object is created via one or multiple
SELECTs
o is an output from multiple functions, methods ...
● For example:
o WP_User (capabilities, user_meta)
o WP_Post ...
Is WordPress cache-ready? It is!
● Transients API
o set_transient, get_transient, delete_transient
o set_site_transient, get_site_transient …
● WP_Object_Cache and wp_cache functions
o wp-includes/cache.php
 wp_cache_add, wp_cache_set,
wp_cache_replace
 wp_cache_get
 wp_cache_delete, wp_cache_flush
Transients API
● temporary saving of cached data
● uses wp_options table by default
o add_option with param autoload = “no”
 if no expiration is set, then autoload = “yes”
o adds two entries to the database
 transient value
 maximal expiration time (vs. guaranted time)
● it’s guaranted by default, but saving into database can be
overriden by memcache server, for instance
● core implementation of this class uses global
variable for saving data
o thus, from nature, is cached only per requests
● has it’s meaning for repeated database
requests
o you can call get_post_meta multiple time for one
request, but you reach database once only
WP_Object_Cache
Where is WP_Object_Cache used
● get_metadata (post, user, comment ...)
● get_option (autoload options)
● get_post, get_user, get_comment, get_term
● transients
● ...
wp_cache functions
● wp_cache_set($key, $data, $group, $expire)
o no expiration by default ($expire = 0)
● wp_cache_get( $key, $group )
o group allows to use same keys across multiple
groups
WP_Object_Cache dropins
● dropins
o wp-content/advanced-cache.php
o wp-content/object-cache.php
● object-cache.php
o prevents loading of wp-includes/wp_cache.php
o redefines WP_Object_Cache and wp_cache
functions
o uses any of external caching engines
 memcache, APC, filesystem ...
oEmbed cache using post_meta
WordPress Cache Plugins
● WP Super Cache http://wordpress.org/plugins/wp-super-
cache/
o page level cache using mod_rewrite
● W3 Total Cache http://wordpress.org/plugins/w3-total-cache/
o multiple object-cache engines
● Batcache http://wordpress.org/plugins/batcache/
● object-cache.php dropins
http://wordpress.org/plugins/memcached/
http://wordpress.org/plugins/apc/
Understanding Cache in WP - Summary
● Memcached, APC, MySQL Query Cache
● Page level vs. Object Cache
o go for a mix of page level and object
cache
● Transients API
● WP_Object_Cache a wp_cache funkce
o dropins: object-cache.php, advanced-cache.php
● oEmbed cache using post_meta table

Contenu connexe

Tendances

Active Data Stores at 30,000ft
Active Data Stores at 30,000ftActive Data Stores at 30,000ft
Active Data Stores at 30,000ftJeffrey Sica
 
Drupal caching
Drupal cachingDrupal caching
Drupal cachingExove
 
JMeter performance and scalability in Moodle Montana Moot 2014
JMeter performance and scalability in Moodle Montana Moot 2014JMeter performance and scalability in Moodle Montana Moot 2014
JMeter performance and scalability in Moodle Montana Moot 2014moorejon
 
Memcached And MySQL
Memcached And MySQLMemcached And MySQL
Memcached And MySQLChris Barber
 
Nano-node: Intelligent Hard Drives in Large Storage Infrastructures
Nano-node: Intelligent Hard Drives in Large Storage InfrastructuresNano-node: Intelligent Hard Drives in Large Storage Infrastructures
Nano-node: Intelligent Hard Drives in Large Storage InfrastructuresOpenIO Object Storage
 
Performance on Rails
Performance on RailsPerformance on Rails
Performance on RailsPedro Sousa
 
Magento Imagine eCommerce Conference February 2011: Optimizing Magento For Pe...
Magento Imagine eCommerce Conference February 2011: Optimizing Magento For Pe...Magento Imagine eCommerce Conference February 2011: Optimizing Magento For Pe...
Magento Imagine eCommerce Conference February 2011: Optimizing Magento For Pe...varien
 
Speed up your site with Varnish
Speed up your site with VarnishSpeed up your site with Varnish
Speed up your site with VarnishSimon Jones
 
20170310 PHP goal pyramid for memorising
20170310 PHP goal pyramid for memorising20170310 PHP goal pyramid for memorising
20170310 PHP goal pyramid for memorisingSharon Liu
 
Mongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricksMongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricksVladimir Malyk
 
Moodle performance testing presentation - Jonathon Moore
 Moodle performance testing presentation - Jonathon Moore Moodle performance testing presentation - Jonathon Moore
Moodle performance testing presentation - Jonathon MooreIreland & UK Moodlemoot 2012
 
Zend Con 2008 Slides
Zend Con 2008 SlidesZend Con 2008 Slides
Zend Con 2008 Slidesmkherlakian
 
S3 & Glacier - The only backup solution you'll ever need
S3 & Glacier - The only backup solution you'll ever needS3 & Glacier - The only backup solution you'll ever need
S3 & Glacier - The only backup solution you'll ever needMatthew Boeckman
 

Tendances (18)

Active Data Stores at 30,000ft
Active Data Stores at 30,000ftActive Data Stores at 30,000ft
Active Data Stores at 30,000ft
 
Drupal caching
Drupal cachingDrupal caching
Drupal caching
 
JMeter performance and scalability in Moodle Montana Moot 2014
JMeter performance and scalability in Moodle Montana Moot 2014JMeter performance and scalability in Moodle Montana Moot 2014
JMeter performance and scalability in Moodle Montana Moot 2014
 
Wordpress install setup
Wordpress install setupWordpress install setup
Wordpress install setup
 
Memcached And MySQL
Memcached And MySQLMemcached And MySQL
Memcached And MySQL
 
Nano-node: Intelligent Hard Drives in Large Storage Infrastructures
Nano-node: Intelligent Hard Drives in Large Storage InfrastructuresNano-node: Intelligent Hard Drives in Large Storage Infrastructures
Nano-node: Intelligent Hard Drives in Large Storage Infrastructures
 
Performance on Rails
Performance on RailsPerformance on Rails
Performance on Rails
 
Magento Imagine eCommerce Conference February 2011: Optimizing Magento For Pe...
Magento Imagine eCommerce Conference February 2011: Optimizing Magento For Pe...Magento Imagine eCommerce Conference February 2011: Optimizing Magento For Pe...
Magento Imagine eCommerce Conference February 2011: Optimizing Magento For Pe...
 
How do i Meet MongoDB
How do i Meet MongoDBHow do i Meet MongoDB
How do i Meet MongoDB
 
Speed up your site with Varnish
Speed up your site with VarnishSpeed up your site with Varnish
Speed up your site with Varnish
 
20170310 PHP goal pyramid for memorising
20170310 PHP goal pyramid for memorising20170310 PHP goal pyramid for memorising
20170310 PHP goal pyramid for memorising
 
Hdfs internals
Hdfs internalsHdfs internals
Hdfs internals
 
Mongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricksMongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricks
 
Moodle performance testing presentation - Jonathon Moore
 Moodle performance testing presentation - Jonathon Moore Moodle performance testing presentation - Jonathon Moore
Moodle performance testing presentation - Jonathon Moore
 
Zend Con 2008 Slides
Zend Con 2008 SlidesZend Con 2008 Slides
Zend Con 2008 Slides
 
Html5-Web-Storage
Html5-Web-StorageHtml5-Web-Storage
Html5-Web-Storage
 
S3 & Glacier - The only backup solution you'll ever need
S3 & Glacier - The only backup solution you'll ever needS3 & Glacier - The only backup solution you'll ever need
S3 & Glacier - The only backup solution you'll ever need
 
Ajax xml json
Ajax xml jsonAjax xml json
Ajax xml json
 

Similaire à Caching in WordPress

Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsUlf Wendel
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesExove
 
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sitesdrupalcampest
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersSeravo
 
Zend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applicationsZend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applicationsEnrico Zimuel
 
Caching in WordPress
Caching in WordPressCaching in WordPress
Caching in WordPressTareq Hasan
 
Data cache management in php
Data cache management in phpData cache management in php
Data cache management in phpAndrew Yatsenko
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APCBen Ramsey
 
Zend Server Data Caching
Zend Server Data CachingZend Server Data Caching
Zend Server Data CachingEl Taller Web
 
Caching Up and Down the Stack
Caching Up and Down the StackCaching Up and Down the Stack
Caching Up and Down the StackDan Kuebrich
 
Caching, Scaling, and What I've Learned from WordPress.com VIP
Caching, Scaling, and What I've Learned from WordPress.com VIPCaching, Scaling, and What I've Learned from WordPress.com VIP
Caching, Scaling, and What I've Learned from WordPress.com VIPErick Hitter
 
Drupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case StudyDrupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case Studyhernanibf
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Wim Godden
 
Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and ScalabilityMediacurrent
 

Similaire à Caching in WordPress (20)

Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
 
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
 
Php
PhpPhp
Php
 
Caching in drupal
Caching in drupalCaching in drupal
Caching in drupal
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developers
 
Php
PhpPhp
Php
 
Zend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applicationsZend_Cache: how to improve the performance of PHP applications
Zend_Cache: how to improve the performance of PHP applications
 
Caching in WordPress
Caching in WordPressCaching in WordPress
Caching in WordPress
 
Data cache management in php
Data cache management in phpData cache management in php
Data cache management in php
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
 
Asp.net caching
Asp.net cachingAsp.net caching
Asp.net caching
 
Zend Server Data Caching
Zend Server Data CachingZend Server Data Caching
Zend Server Data Caching
 
Caching Up and Down the Stack
Caching Up and Down the StackCaching Up and Down the Stack
Caching Up and Down the Stack
 
Caching, Scaling, and What I've Learned from WordPress.com VIP
Caching, Scaling, and What I've Learned from WordPress.com VIPCaching, Scaling, and What I've Learned from WordPress.com VIP
Caching, Scaling, and What I've Learned from WordPress.com VIP
 
Caching
CachingCaching
Caching
 
Scaling PHP apps
Scaling PHP appsScaling PHP apps
Scaling PHP apps
 
Drupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case StudyDrupal Performance - SerBenfiquista.com Case Study
Drupal Performance - SerBenfiquista.com Case Study
 
Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011Caching and tuning fun for high scalability @ phpBenelux 2011
Caching and tuning fun for high scalability @ phpBenelux 2011
 
Performance and Scalability
Performance and ScalabilityPerformance and Scalability
Performance and Scalability
 

Dernier

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 

Dernier (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 

Caching in WordPress

  • 2. Presentation outline ● What cache is, what to cache ● Caching options in PHP and MySQL o Memcached, Alternative PHP Cache (APC) o MySQL Query Cache ● Page level a Object Cache ● Is WordPress cache-ready? o Transients API o WP_Object_Cache a wp_cache funkce o oEmbed cache
  • 3. What is a cache and what to cache? ● transparently stored data so that future requests for that data can be served faster ● You can cache almost everything o whole pages, objects o external API requests, resource demanding operations ... ● … and even more o MySQL Query Cache o OpCode
  • 4. MySQL Query Cache ● only identical and deterministic SELECT requests ● inter session persistent ● cache flushing after the change of relevant data ● non-distributed
  • 5. Cache engines ● Memcached o distributed (server accessible via telnet) o key-value pairs saved in a memory o PECL extension for PHP (memcached / memcache) ● Alternative PHP Cache (APC) o Opcode and user cache (PHP <= 5.4), APCu (PHP 5.5) o non-distributed ● Flat file o eg. mod_rewrite (WP Super Cache), CDN
  • 6. Page Level vs. Object Cache ● Page level cache (e.g. WP Super Cache) o saves only whole pages o every single page has to be generated on it’s own with all database requests, API call etc.. o usually is not available for non logged in users ● Object cache (APC, Memcached, W3TC) o reusable for a generation of multiple pages o works also for logged in users o has affect even on WordPress administration
  • 7. Page Level Cache ● HTML files saved on hard drive o loading via PHP or mod_rewrite (WP Super Cache) ● memcached (Batcache) o can be used even without PHP (NginX, Apache ...) ● CDN o cloudflare (W3TC) o anything else (WP Super Cache)
  • 8. How to cache a page in WordPress
  • 9. WP Super Cache - mod_rewrite
  • 10. Object Cache ● reusable objects o either in terms of a single requests o or, and with better performance, in multiple requests ● object is created via one or multiple SELECTs o is an output from multiple functions, methods ... ● For example: o WP_User (capabilities, user_meta) o WP_Post ...
  • 11. Is WordPress cache-ready? It is! ● Transients API o set_transient, get_transient, delete_transient o set_site_transient, get_site_transient … ● WP_Object_Cache and wp_cache functions o wp-includes/cache.php  wp_cache_add, wp_cache_set, wp_cache_replace  wp_cache_get  wp_cache_delete, wp_cache_flush
  • 12. Transients API ● temporary saving of cached data ● uses wp_options table by default o add_option with param autoload = “no”  if no expiration is set, then autoload = “yes” o adds two entries to the database  transient value  maximal expiration time (vs. guaranted time) ● it’s guaranted by default, but saving into database can be overriden by memcache server, for instance
  • 13. ● core implementation of this class uses global variable for saving data o thus, from nature, is cached only per requests ● has it’s meaning for repeated database requests o you can call get_post_meta multiple time for one request, but you reach database once only WP_Object_Cache
  • 14. Where is WP_Object_Cache used ● get_metadata (post, user, comment ...) ● get_option (autoload options) ● get_post, get_user, get_comment, get_term ● transients ● ...
  • 15. wp_cache functions ● wp_cache_set($key, $data, $group, $expire) o no expiration by default ($expire = 0) ● wp_cache_get( $key, $group ) o group allows to use same keys across multiple groups
  • 16. WP_Object_Cache dropins ● dropins o wp-content/advanced-cache.php o wp-content/object-cache.php ● object-cache.php o prevents loading of wp-includes/wp_cache.php o redefines WP_Object_Cache and wp_cache functions o uses any of external caching engines  memcache, APC, filesystem ...
  • 17. oEmbed cache using post_meta
  • 18. WordPress Cache Plugins ● WP Super Cache http://wordpress.org/plugins/wp-super- cache/ o page level cache using mod_rewrite ● W3 Total Cache http://wordpress.org/plugins/w3-total-cache/ o multiple object-cache engines ● Batcache http://wordpress.org/plugins/batcache/ ● object-cache.php dropins http://wordpress.org/plugins/memcached/ http://wordpress.org/plugins/apc/
  • 19. Understanding Cache in WP - Summary ● Memcached, APC, MySQL Query Cache ● Page level vs. Object Cache o go for a mix of page level and object cache ● Transients API ● WP_Object_Cache a wp_cache funkce o dropins: object-cache.php, advanced-cache.php ● oEmbed cache using post_meta table

Notes de l'éditeur

  1. http://dev.mysql.com/doc/refman/5.1/en/query-cache.html
  2. http://memcached.org/ http://www.php.net/manual/en/book.apc.php http://pecl.php.net/package/memcached
  3. http://nginx.org/en/docs/http/ngx_http_memcached_module.html http://httpd.apache.org/docs/2.2/mod/mod_mem_cache.html
  4. This is just a pseudo non working code showing principles of using PHP’s output buffer with a callback and advanced-cache.php dropin.
  5. Example of mod_rewrites generated by WP Super Cache plugin for serving previously cached (saved) page
  6. http://codex.wordpress.org/Transients_API http://codex.wordpress.org/Class_Reference/WP_Object_Cache
  7. http://codex.wordpress.org/Transients_API
  8. http://codex.wordpress.org/Class_Reference/WP_Object_Cache
  9. This is a stripped code from the WordPress core