2026年11月13日
2026年11月13日
WordPress Cache Plugin Setup: W3 Total Cache, LiteSpeed, WP Rocket
This article is a localized edition of the Japanese original. Read the Japanese original
Caching stores pages or data once they are built and reuses them on later requests. Normally WordPress runs PHP and queries the database to assemble the page on every request. Caching skips that work, so pages load faster and the server carries less load.
The settings and results in this article were checked on WordPress 7.1, W3 Total Cache 2.11, LiteSpeed Cache 7.9, Redis Object Cache 3.0 and WooCommerce 11.2 as of November 2026. (WP Rocket is a paid plugin, so that part is based on its official documentation.)
Types of cache
| Type | What it stores | Main tools |
|---|---|---|
| Page cache | The full HTML of a page | Cache plugins, server-side caching |
| Browser cache | Images, CSS and JavaScript stored in the visitor's browser | HTTP headers (set by a plugin or .htaccess) |
| Object cache | Database query results and similar data | Redis or Memcached plus a plugin |
| Transients | Temporary data saved by plugins and themes | Transients API (set_transient() and friends) |
Page caching has the biggest effect on speed. Logged-out visitors get the saved HTML as is.
Choosing a plugin
- If your server runs LiteSpeed (including OpenLiteSpeed): Use LiteSpeed Cache. Its page cache runs in the server, so it only works on a LiteSpeed server (or through the QUIC.cloud CDN). On Apache or Nginx you only get the general features, such as image optimization and CSS/JavaScript minification.
- On Apache or Nginx: Free options include W3 Total Cache and WP Super Cache; WP Rocket is a paid option.
- If your host offers caching: Use the host's server-side cache first, and avoid running a plugin's page cache on top of it.
Use only one page cache plugin. With two or more active, you cannot tell which cache is serving the page, and updates may not show up. For a comparison, see WordPress cache plugins compared.
Basic W3 Total Cache setup
- Go to Plugins → Add Plugin, search for "W3 Total Cache", then install and activate it.
- Open Performance → General Settings in the admin.
- Under Page Cache, enable it and choose "Disk: Enhanced" as the method.
- Click "Save all settings".
With "Disk: Enhanced", cached HTML is stored in wp-content/cache/page_enhanced/ and Apache serves it directly using rules written to .htaccess. For that, W3 Total Cache writes define('WP_CACHE', true); to wp-config.php and cache rules to .htaccess (in our test, both files had been updated after activation and setup). If wp-config.php is read-only, for example 440, allow writing while you configure the plugin.
In our test, when we opened the same page while logged out, the second and later requests were served from cache, with a comment like this at the end of the HTML.
<!-- Performance optimized by W3 Total Cache. ...
Page Caching using Disk: Enhanced
Served from: localhost @ 2026-11-10 10:30:36 by W3 Total Cache -->
By default, cached pages are not served to logged-in users. To clear the cache, use Performance → Purge All Caches in the admin bar, or run this WP-CLI command.
wp w3-total-cache flush all
For detailed settings, see how to configure W3 Total Cache.
Basic LiteSpeed Cache setup
- Go to Plugins → Add Plugin, search for "LiteSpeed Cache", then install and activate it.
- Open LiteSpeed Cache → Cache in the admin.
- Turn "Enable Cache" on and save.
When a LiteSpeed server serves a page from cache, the X-LiteSpeed-Cache response header shows hit. "Cache Logged-in Users" is on by default, and logged-in users get a separate per-user cache (the private cache). To keep URLs out of the cache, list them in "Do Not Cache URIs" on the Excludes tab of the same screen.
To purge the whole cache, use the admin bar menu or this WP-CLI command.
wp litespeed-purge all
For details, see how to configure LiteSpeed Cache.
Basic WP Rocket setup
WP Rocket is a paid plugin. Buy it on the official site, download the ZIP file, and install it via Add Plugin → Upload Plugin. According to its documentation, page caching is turned on automatically when you activate it. The settings are under Settings → WP Rocket, and URLs or cookies to exclude from the cache go in the "Advanced Rules" section.
For detailed settings, see how to configure WP Rocket.
Exclude pages that must not be cached
Caching pages whose content differs per visitor, such as the cart, checkout or member pages, causes problems like showing someone else's cart.
WooCommerce pages
WooCommerce defines the DONOTCACHEPAGE constant on the Cart, Checkout and My Account pages (confirmed in the WooCommerce 11.2 source). W3 Total Cache, LiteSpeed Cache and WP Rocket all respect this constant and skip caching, so these pages are normally excluded without extra settings.
The official WooCommerce documentation still recommends excluding the Cart, My Account and Checkout pages in your cache plugin's settings, and not serving cached pages to visitors with these cookies.
woocommerce_cart_hashwoocommerce_items_in_cartwp_woocommerce_session_
Exclude your own pages
You can use the same constant to exclude pages you built yourself, such as a form confirmation page. Add this to a child theme's functions.php or similar.
<?php
// Exclude the page with the slug contact-confirm from page caching
add_action( 'template_redirect', function () {
if ( is_page( 'contact-confirm' ) && ! defined( 'DONOTCACHEPAGE' ) ) {
define( 'DONOTCACHEPAGE', true );
}
} );
In our test, W3 Total Cache created no cache file for the page, and the comment at the end of the HTML said "DONOTCACHEPAGE constant is defined".
Only plugins running inside WordPress look at this constant, though. If caching happens outside WordPress, such as the Nginx FastCGI cache or a CDN, exclude the URLs in that layer's configuration.
Use Redis for object caching
An object cache keeps database query results and similar data in memory. It also helps where page caching does not apply, such as logged-in screens, the admin and WooCommerce carts. Use it on servers where you can install Redis, such as a VPS (Ubuntu example).
sudo apt install redis-server php-redis
sudo systemctl enable --now redis-server
redis-cli ping # It is running if it replies PONG
Add the connection settings to wp-config.php above the "That's all, stop editing!" line.
<?php
define( 'WP_REDIS_HOST', '127.0.0.1' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_PREFIX', 'example_com:' ); // Use a different value per site when several sites share one Redis
Next, install and activate the Redis Object Cache plugin and enable the object cache (WP-CLI example).
wp plugin install redis-cache --activate
wp redis enable
wp redis status
In our test, wp redis status reported Status: Connected and the wp-content/object-cache.php drop-in was installed. Transients are then stored in Redis instead of the database (check with wp transient type). Even without the PHP Redis extension (php-redis), the plugin connected using its bundled Predis client.
To clear it, use wp cache flush. For details, see how to set up Redis caching for WordPress.
Store expensive results in transients
If a plugin or theme calls an external API or runs a heavy query on every request, saving the result in a transient reduces the load.
<?php
/**
* Return IDs of the most viewed posts (custom field _myprefix_views), cached for 1 hour
*/
function myprefix_get_popular_post_ids( $limit = 5 ) {
$limit = absint( $limit );
$cache_key = 'myprefix_popular_' . $limit;
$ids = get_transient( $cache_key );
if ( false !== $ids ) {
return $ids;
}
$ids = get_posts(
array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $limit,
'meta_key' => '_myprefix_views',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'fields' => 'ids',
'no_found_rows' => true,
)
);
set_transient( $cache_key, $ids, HOUR_IN_SECONDS );
return $ids;
}
// Clear the cache when a post is saved
add_action( 'save_post_post', function ( $post_id ) {
if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
return;
}
foreach ( array( 5, 10 ) as $limit ) {
delete_transient( 'myprefix_popular_' . $limit );
}
} );
Transients are covered in detail in how to use transients in a WordPress plugin.
Check that caching works
Test page caching while logged out. A browser logged in to the admin usually gets uncached pages.
# Fetch twice in a row and compare the response headers
curl -sI https://example.com/
curl -sI https://example.com/
# Look at the end of the HTML (comments from W3 Total Cache and others)
curl -s https://example.com/ | tail -n 3
- LiteSpeed Cache: If the second response has
X-LiteSpeed-Cache: hit, it came from the cache. - W3 Total Cache: If the "Served from" time in the closing HTML comment stays the same as the first request, the page came from the cache.
- If you use a CDN, also check its response header (
cf-cache-statusfor Cloudflare).
Check transients and the object cache with WP-CLI.
wp transient list --human-readable # List transients stored in the database
wp transient delete --expired # Delete expired transients
wp cache type # Show which object cache is in use
Day-to-day cautions
- Clear the cache after updates: If the site does not change after a theme or plugin update, clear the cache and check again.
- Nonces in pages: Cached HTML keeps the nonce (the check value used by forms and Ajax) from when it was generated. If you cache longer than a nonce stays valid (up to 24 hours by default), form submissions and similar actions can fail.
- CSS/JavaScript minification and combining: If a cache plugin's optimization features break the layout, turn off just that feature to isolate the cause.
Related articles
Questions about WordPress? The publisher of this site is based in Japan and replies in Japanese. Contact (Japanese)