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

Mais conteúdo relacionado

Mais procurados

Drupal caching
Drupal cachingDrupal caching
Drupal caching
Exove
 

Mais procurados (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
 

Semelhante a Caching in WordPress

Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance SitesDrupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
drupalcampest
 

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

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

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

Notas do Editor

  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