SlideShare a Scribd company logo
Caching in WordPress 
Tareq Hasan (@tareq_cse) 
http://tareq.weDevs.com
What is Caching? 
• Serve static content to the visitor without querying 
the database. 
• Not generated upon **every** request 
• Reduce to API calls
Type of Caching? 
• Page Cache - Whole page as static content 
• Query Cache - Cache SQL query results 
• Fragment Cache - Cache a piece of page 
• Browser Cache - Cache page assets 
• Opcode Cache - PHP executes faster
WordPress Caching APIs 
Transients! 
- Persistent out of the box 
- Stored in wp_options 
get_transient() 
set_transient() 
delete_transient() 
Object Cache! 
- Not persistent without a 
persistent backend 
- Storage depends on the 
backend 
wp_cache_add() 
wp_cache_set() 
wp_cache_get() 
wp_cache_delete()
Using Transients 
set_transient( $key, $value, $expiration ); 
<?php 
// Get any existing copy of our transient data 
$special_query = get_transient( 'special_query' ); 
if ( false === $special_query_results ) { 
$special_query = new WP_Query( 'cat=5&order=random' ); 
set_transient( 'special_query', $special_query, 12 * HOUR_IN_SECONDS ); 
} 
// Use the data like you would have normally... 
Queries only after each 12 hours
Object Cache 
• Not persistent. Means, valid for only one pageload 
• Requires a persistent backend. Such as APC, 
Memcached. 
• Plugins like W3 Total Cache, Memcached Object 
Cache helps. 
• Used Extensively in WordPress 
• Cache objects can be grouped
Object Cache Functions 
// set the cache with value 
wp_cache_add( $key, $data, $group, $expire ) 
wp_cache_set( $key, $data, $group, $expire ) 
// retrieve the value from cache 
wp_cache_get( $key, $group ) 
// clears data from the cache for the given key. 
wp_cache_replace( $key, $data, $group, $expire ) 
// clears all cached data. 
wp_cache_flush()
Using Object Cache 
$result = wp_cache_get( 'my_result' ); 
if ( false === $result ) { 
$result = $wpdb->get_results( $query ); 
wp_cache_set( 'my_result', $result ); 
} 
// Do something with $result; 
http://codex.wordpress.org/Class_Reference/WP_Object_Cache
Persistent Cache Plugins 
• W3 Total Cache 
• WP File Cache 
• Memcached Object Cache 
• APC Object Cache 
• WordPress Redis Backend
Fragment Caching 
• Cache a fragment of a page 
• This could be your menubar, widgets and other 
query related parts. 
https://gist.github.com/markjaquith/2653957
Browser Caching 
• HTTP Cache-Control 
• Expiry Headers 
• Entity Tags 
(W3-Total-Cache, WP Super Cache) 
http://www.mobify.com/blog/beginners-guide-to-http-cache-headers/
Opcode Cache 
php-apc + W3 Total Cache
Questions?

More Related Content

PDF
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
PDF
10 things every developer should know about their database to run word press ...
PDF
The wp config.php
PPTX
Presentation to SAIT Students - Dec 2013
PDF
AmazonS3 & Rails
PDF
WordPress Server Security
PDF
Write your first WordPress plugin
PDF
WordCamp Finland 2015 - WordPress Security
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
10 things every developer should know about their database to run word press ...
The wp config.php
Presentation to SAIT Students - Dec 2013
AmazonS3 & Rails
WordPress Server Security
Write your first WordPress plugin
WordCamp Finland 2015 - WordPress Security

What's hot (20)

PPTX
Php basics
ODP
Drupal Multi-site for Fun and Profit
PDF
Getting Started with WP-CLI, a tool to automate your life
KEY
Doing Things the WordPress Way
PDF
Php workshop L04 database
PPTX
Working with WP_Query in WordPress
PDF
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
PDF
Php workshop L03 superglobals
PDF
Extending the WordPress REST API - Josh Pollock
PDF
Entry-level PHP for WordPress
PDF
You Don't Know Query - WordCamp Portland 2011
PPTX
Integrating External APIs with WordPress
PDF
Selenium sandwich-2
PDF
Selenium Sandwich Part 1: Data driven Selenium
PDF
WordCamp SF 2011: Debugging in WordPress
PDF
Htaccess file tutorial and tips
PDF
Integrating WordPress With Web APIs
PPTX
Week3 adb
PDF
Technical SEO: .htaccess & 301 Redirects
PPTX
Ithemes presentation
Php basics
Drupal Multi-site for Fun and Profit
Getting Started with WP-CLI, a tool to automate your life
Doing Things the WordPress Way
Php workshop L04 database
Working with WP_Query in WordPress
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
Php workshop L03 superglobals
Extending the WordPress REST API - Josh Pollock
Entry-level PHP for WordPress
You Don't Know Query - WordCamp Portland 2011
Integrating External APIs with WordPress
Selenium sandwich-2
Selenium Sandwich Part 1: Data driven Selenium
WordCamp SF 2011: Debugging in WordPress
Htaccess file tutorial and tips
Integrating WordPress With Web APIs
Week3 adb
Technical SEO: .htaccess & 301 Redirects
Ithemes presentation
Ad

Viewers also liked (20)

PDF
Intro to advanced caching in WordPress
ODP
La empresa y el mercado
PDF
EXPERIENCIA EN LA IMPLEMENTACIÓN DE LA VUCE COLOMBIA
PPT
Planificacion de Proyectos Civiles
PDF
PAA 2016 Musical Theatre Flyer
PDF
Forrester research report
PDF
Risk Ecosystem Survey Infographic
PPT
Issue desk slides summer 11
PPT
Mliven AlsoMobile.com
PPT
زندگی پس از زندگی
PDF
Propuesta curricular-baja
PPS
Muse Score
PDF
Trable programatora
PPTX
Terminologia arancelaria
PDF
Public Opinion Landscape: Election 2016
PPTX
Le mobile en passe de devenir un device médical
PPTX
Salesforce for B2C
PPTX
La Formazione e l’aggiornamento professionale dei docenti in eTwinning e co...
PPTX
Our presentation on algorithm design
PPT
Sistema de inspección, regulaciones y procedimientos para la importación de f...
Intro to advanced caching in WordPress
La empresa y el mercado
EXPERIENCIA EN LA IMPLEMENTACIÓN DE LA VUCE COLOMBIA
Planificacion de Proyectos Civiles
PAA 2016 Musical Theatre Flyer
Forrester research report
Risk Ecosystem Survey Infographic
Issue desk slides summer 11
Mliven AlsoMobile.com
زندگی پس از زندگی
Propuesta curricular-baja
Muse Score
Trable programatora
Terminologia arancelaria
Public Opinion Landscape: Election 2016
Le mobile en passe de devenir un device médical
Salesforce for B2C
La Formazione e l’aggiornamento professionale dei docenti in eTwinning e co...
Our presentation on algorithm design
Sistema de inspección, regulaciones y procedimientos para la importación de f...
Ad

Similar to Caching in WordPress (20)

PPTX
Caching, Scaling, and What I've Learned from WordPress.com VIP
PPTX
Caching in WordPress
PDF
The Need For Speed: Caching Fundamentals
PDF
Cache Rules Everything Around Me
PDF
Caching and Scaling WordPress using Fragment Caching
PPTX
Consuming & embedding external content in WordPress
PDF
Improve WordPress performance with caching and deferred execution of code
PDF
Options, and Transients, and Theme Mods — Oh my!
ODP
Caching and tuning fun for high scalability
PDF
Balancing Act of Caching, WordCamp Europe 2018
PDF
Speed Things Up with Transients
PDF
Optimizing WordPress for Performance - WordCamp Houston
PDF
Less and faster – Cache tips for WordPress developers
KEY
Introduction to memcached
PDF
Balancing Act of Caching LoopConf 2018
PPTX
Show Me The Cache!
PDF
From Cache to Ca$h - Advanced use of WP Cache - Andrea Cardinali
PPTX
Caching WordPress - Anthony Burchell Wordcamp Presentation
PDF
Introduction to WordPress object caching
ODP
phptek13 - Caching and tuning fun tutorial
Caching, Scaling, and What I've Learned from WordPress.com VIP
Caching in WordPress
The Need For Speed: Caching Fundamentals
Cache Rules Everything Around Me
Caching and Scaling WordPress using Fragment Caching
Consuming & embedding external content in WordPress
Improve WordPress performance with caching and deferred execution of code
Options, and Transients, and Theme Mods — Oh my!
Caching and tuning fun for high scalability
Balancing Act of Caching, WordCamp Europe 2018
Speed Things Up with Transients
Optimizing WordPress for Performance - WordCamp Houston
Less and faster – Cache tips for WordPress developers
Introduction to memcached
Balancing Act of Caching LoopConf 2018
Show Me The Cache!
From Cache to Ca$h - Advanced use of WP Cache - Andrea Cardinali
Caching WordPress - Anthony Burchell Wordcamp Presentation
Introduction to WordPress object caching
phptek13 - Caching and tuning fun tutorial

More from Tareq Hasan (20)

PPTX
Grow Your Career with WordPress
PDF
How to Submit a plugin to WordPress.org Repository
PDF
Composer - The missing package manager for PHP
PPT
08 c++ Operator Overloading.ppt
PPT
02 c++ Array Pointer
PPT
01 c++ Intro.ppt
PPT
chapter22.ppt
PPT
chapter - 6.ppt
PPT
Algorithm.ppt
PPT
chapter-8.ppt
PPT
chapter23.ppt
PPT
chapter24.ppt
PPT
Algorithm: priority queue
PPT
Algorithm: Quick-Sort
PPT
Java: GUI
PPT
Java: Inheritance
PPT
Java: Exception
PPT
Java: Introduction to Arrays
PPT
Java: Class Design Examples
PPT
Java: Objects and Object References
Grow Your Career with WordPress
How to Submit a plugin to WordPress.org Repository
Composer - The missing package manager for PHP
08 c++ Operator Overloading.ppt
02 c++ Array Pointer
01 c++ Intro.ppt
chapter22.ppt
chapter - 6.ppt
Algorithm.ppt
chapter-8.ppt
chapter23.ppt
chapter24.ppt
Algorithm: priority queue
Algorithm: Quick-Sort
Java: GUI
Java: Inheritance
Java: Exception
Java: Introduction to Arrays
Java: Class Design Examples
Java: Objects and Object References

Recently uploaded (20)

PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
System and Network Administration Chapter 2
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
history of c programming in notes for students .pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
ai tools demonstartion for schools and inter college
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Navsoft: AI-Powered Business Solutions & Custom Software Development
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
System and Network Administration Chapter 2
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
How Creative Agencies Leverage Project Management Software.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
L1 - Introduction to python Backend.pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
How to Choose the Right IT Partner for Your Business in Malaysia
Design an Analysis of Algorithms II-SECS-1021-03
VVF-Customer-Presentation2025-Ver1.9.pptx
history of c programming in notes for students .pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
ai tools demonstartion for schools and inter college
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)

Caching in WordPress

  • 1. Caching in WordPress Tareq Hasan (@tareq_cse) http://tareq.weDevs.com
  • 2. What is Caching? • Serve static content to the visitor without querying the database. • Not generated upon **every** request • Reduce to API calls
  • 3. Type of Caching? • Page Cache - Whole page as static content • Query Cache - Cache SQL query results • Fragment Cache - Cache a piece of page • Browser Cache - Cache page assets • Opcode Cache - PHP executes faster
  • 4. WordPress Caching APIs Transients! - Persistent out of the box - Stored in wp_options get_transient() set_transient() delete_transient() Object Cache! - Not persistent without a persistent backend - Storage depends on the backend wp_cache_add() wp_cache_set() wp_cache_get() wp_cache_delete()
  • 5. Using Transients set_transient( $key, $value, $expiration ); <?php // Get any existing copy of our transient data $special_query = get_transient( 'special_query' ); if ( false === $special_query_results ) { $special_query = new WP_Query( 'cat=5&order=random' ); set_transient( 'special_query', $special_query, 12 * HOUR_IN_SECONDS ); } // Use the data like you would have normally... Queries only after each 12 hours
  • 6. Object Cache • Not persistent. Means, valid for only one pageload • Requires a persistent backend. Such as APC, Memcached. • Plugins like W3 Total Cache, Memcached Object Cache helps. • Used Extensively in WordPress • Cache objects can be grouped
  • 7. Object Cache Functions // set the cache with value wp_cache_add( $key, $data, $group, $expire ) wp_cache_set( $key, $data, $group, $expire ) // retrieve the value from cache wp_cache_get( $key, $group ) // clears data from the cache for the given key. wp_cache_replace( $key, $data, $group, $expire ) // clears all cached data. wp_cache_flush()
  • 8. Using Object Cache $result = wp_cache_get( 'my_result' ); if ( false === $result ) { $result = $wpdb->get_results( $query ); wp_cache_set( 'my_result', $result ); } // Do something with $result; http://codex.wordpress.org/Class_Reference/WP_Object_Cache
  • 9. Persistent Cache Plugins • W3 Total Cache • WP File Cache • Memcached Object Cache • APC Object Cache • WordPress Redis Backend
  • 10. Fragment Caching • Cache a fragment of a page • This could be your menubar, widgets and other query related parts. https://gist.github.com/markjaquith/2653957
  • 11. Browser Caching • HTTP Cache-Control • Expiry Headers • Entity Tags (W3-Total-Cache, WP Super Cache) http://www.mobify.com/blog/beginners-guide-to-http-cache-headers/
  • 12. Opcode Cache php-apc + W3 Total Cache