A technical guide to server-side, object, and page caching in WordPress – including plugins, transients, and external cache layers.
Caching is the cornerstone of a high-performance WordPress site. Done right, it can dramatically reduce load times and server costs.
This guide breaks down the core types of caching and how to implement them properly.
1. Page Caching (Full HTML)
Generates static HTML versions of dynamic pages.
Tools:
- FlyingPress
- WP Rocket
- Cache Enabler (lightweight)
- Nginx FastCGI Cache (server-level)
location ~* \.(?:html)$ {
expires 1h;
add_header Cache-Control "public";
}
Benefits:
- Reduces PHP/MySQL usage
- Instant response for anonymous users
2. Object Caching (Persistent)
Stores repeated database query results in memory.
Options:
- Redis via
Redis Object Cache - Memcached via
Batcacheor custom
wp_cache_set( 'key', $data, 'group', 3600 );
$data = wp_cache_get( 'key', 'group' );
Use for:
- Custom queries
- Expensive ACF lookups
- WooCommerce product filters
3. Transients API
A database-backed way to cache key-value pairs.
set_transient( 'top_posts', $query, HOUR_IN_SECONDS );
Use sparingly for time-sensitive data like:
- Third-party API calls
- Custom loops
- Analytics summaries
Tip: Use site_transient_ for multisite.
4. Opcode Caching
PHP-level caching using OPcache:
- Enabled by default on most hosts
- Improves script compilation speed
Check with:
phpinfo(); // Look for OPcache section
5. CDN Caching (Edge Layer)
Use Cloudflare, BunnyCDN, or KeyCDN to cache:
- Images
- Static files (CSS/JS)
- Entire HTML pages (with page rules)
Cloudflare example rule:
URL pattern: *example.com/blog/*
Cache Level: Cache Everything
Edge TTL: 1 hour
6. Cache Invalidation
Always plan for:
- Purging on post/page update
- Bypass for logged-in users
- Stale cache detection for WooCommerce carts
Plugins like FlyingPress and WP Rocket handle this smartly. Custom hooks can help:
add_action('save_post', 'clear_post_cache');
7. Layered Strategy Example
For a high-traffic WooCommerce store:
- Page cache for anonymous traffic (FlyingPress)
- Object cache via Redis for dynamic product filters
- Transients for top categories
- Cloudflare edge caching for blog content