WordPress Dynamic Site Caching Configuration

Complete Guide for NGINX, WP Super Cache, and Redis Object Cache

Overview

The process of installing and configuring a caching plugin for a dynamic WordPress site is similar to that of a static site. However, there are critical differences in managing cache exclusions to maintain the accuracy of dynamic content, particularly for e-commerce platforms like WooCommerce.

Key Differences for Dynamic Sites:
  • Defining and managing cache exclusions for dynamic content
  • Configuring object caching using Redis
  • Excluding specific URLs and cookies from the cache
  • Ensuring accurate functionality for shopping carts and user sessions

Caching Architecture for Dynamic WordPress Sites

NGINX Server
WP Super Cache (Page Cache)
Redis Object Cache
WordPress Application
MySQL Database

Step 1: Configure NGINX Server Block

1Navigate to NGINX Configuration Directory

cd /etc/nginx/sites-available

2Open Your Site's Server Block File

sudo nano example.com.conf

3View WP Super Cache Excludes File

cd /etc/nginx/includes
sudo cat wp_super_cache_excludes.conf
readlink -f wp_super_cache_excludes.conf

4Modify Server Block Configuration

In your server block file, make the following changes:

# Comment out the default location context
#location / {
#    try_files $uri $uri/ /index.php$is_args$args;
#}

# Add WP Super Cache includes file above PHP processing location
include /etc/nginx/includes/wp_super_cache_excludes.conf;

5Test and Reload NGINX

sudo nginx -t
sudo systemctl reload nginx
Success: NGINX is now configured to work with WP Super Cache.

Step 2: Install and Configure WP Super Cache Plugin

1Install the Plugin

  1. Open your WordPress Dashboard
  2. Navigate to Plugins → Add New Plugin
  3. Search for "WP Super Cache"
  4. Click Install Now
  5. Click Activate

2Initial Configuration

  1. Go to Settings → WP Super Cache
  2. Click Caching On
  3. Click Update Status
  4. Click Test Cache to verify functionality
Note: Verify that timestamps on both test pages match and that advanced caching is enabled.

3Advanced Settings

Switch to Expert Mode and configure the following options:

  • Don't cache pages with GET parameters - Enable this option
  • Compress pages - Enable for faster serving
  • 304 Browser Caching - Enable under Advanced tab
  • Clear cache on post/page update - Enable this option
Click "Update Status" after each configuration change

4Preload Configuration

  1. Go to the Preload tab
  2. Enable preload mode
  3. Enable both preload options
  4. Click Save Settings

5Debug Settings

  1. Go to the Debug tab
  2. Ensure Cache Status Messages is enabled
  3. Click Save Settings

Step 3: Configure WooCommerce Cache Exclusions

Reference: Visit WooCommerce Caching Documentation for official guidelines.

1Exclude Critical URLs

Navigate to Settings → WP Super Cache → Advanced tab. In the Rejected URL Strings section, add the following URLs:

/cart/
/my-account/
/checkout/
Click "Save Strings" after adding URLs

2Exclude WooCommerce Cookies

In the Rejected Cookies section, add the following cookies:

woocommerce_cart_hash
woocommerce_items_in_cart
wp_woocommerce_session_
woocommerce_recently_viewed
store_notice[notice id]
Click "Save" after adding cookies
Important: These exclusions ensure that shopping cart data, user accounts, and checkout processes are not cached, maintaining accurate functionality for your e-commerce site.
Exclusion Type Purpose Example
URL Strings Prevent caching of dynamic pages /cart/, /checkout/
Cookies Maintain user session data woocommerce_cart_hash
Session Data Exclude from object cache wc_session

Step 4: Configure wp-config.php for Redis

1Navigate to Document Root

cd /var/www/example.com/public_html

2Edit wp-config.php File

sudo nano wp-config.php

3Add WP Cache Key Salt

Scroll to the salt section and add the following constant:

define('WP_CACHE_KEY_SALT', 'example.com');
Purpose: The WP_CACHE_KEY_SALT constant adds a unique identifier to cache keys, ensuring they are specific to your WordPress site and preventing conflicts with other sites on the same server.

4Exclude WooCommerce Session from Redis Cache

Scroll down to the custom constants section (above "/* That's all, stop editing! */") and add:

/** PREVENT REDIS CACHING WOO SESSION DATA */
define('WP_REDIS_IGNORED_GROUPS', 'wc_session');
Critical: The wc_session cookie is used by WooCommerce for maintaining user sessions and managing shopping cart data. It must be excluded from Redis object cache to prevent cart data issues.

5Save and Reload PHP-FPM

sudo systemctl reload php8.3-fpm

Step 5: Install and Configure Redis Object Cache Plugin

1Install Redis Object Cache Plugin

  1. Navigate to Plugins → Add New Plugin
  2. Search for "Redis Object Cache"
  3. Click Install Now
  4. Click Activate

2Enable Object Cache

  1. Go to Settings → Redis
  2. Status will show "Not Enabled"
  3. Click Enable Object Cache

3Verify Configuration

After enabling, verify the following statuses:

  • Status: Connected
  • File System: Writeable
  • Redis: Reachable

4Check Diagnostics

Select the Diagnostics tab and verify:

WP Redis Prefix: example.com
WP Redis Ignored Groups: wc_session
Configuration Complete! You have successfully set up page caching with WP Super Cache and Redis Object Cache with all necessary WooCommerce exclusions.

Cache Exclusion Flow for WooCommerce

User Request
Check URL (/cart/, /checkout/, etc.)
Check Cookies (woocommerce_cart_hash, etc.)
Bypass Cache if Match Found
Serve Dynamic Content from PHP

Step 6: Additional Optimizations

CSS and JavaScript Minification

For further optimization, install a minification plugin:

  1. Navigate to Plugins → Add New Plugin
  2. Search for a minification plugin (e.g., "Autoptimize")
  3. Install and configure according to your needs
Note: Test your site thoroughly after enabling minification to ensure no functionality is broken.

Uninstalling WP Super Cache and Redis Object Cache

Critical Warning: Always follow the correct uninstallation procedure for caching plugins. Improper removal can leave behind configuration files and directories that may cause conflicts with future caching solutions.

1Deactivate Redis Object Cache Plugin

  1. Go to Plugins → Installed Plugins
  2. Find "Redis Object Cache"
  3. Click Deactivate
  4. Click Delete

2Clean Up wp-config.php

cd /var/www/example.com/public_html
sudo nano wp-config.php

Remove the following lines:

define('WP_CACHE_KEY_SALT', 'example.com');

/** PREVENT REDIS CACHING WOO SESSION DATA */
define('WP_REDIS_IGNORED_GROUPS', 'wc_session');

3Reload PHP-FPM

sudo systemctl reload php8.3-fpm

4Disable WP Super Cache

  1. Go to Settings → WP Super Cache
  2. Click Turn Off Caching
  3. Click Update Status
  4. Click Clear Cache

5Deactivate and Delete WP Super Cache

  1. Go to Plugins → Installed Plugins
  2. Find "WP Super Cache"
  3. Click Deactivate
  4. Click Delete

6Update NGINX Server Block

cd /etc/nginx/sites-available
sudo nano example.com.conf

Make the following changes:

# Uncomment the default location context
location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

# Remove the WP Super Cache includes directive
# include /etc/nginx/includes/wp_super_cache_excludes.conf;

7Test and Reload NGINX

sudo nginx -t
sudo systemctl reload nginx
Optional: The wp_super_cache_excludes.conf file in /etc/nginx/includes/ can remain on the server for future use. It will not affect the site unless explicitly included in a server block.

Best Practices and Recommendations

For Any Dynamic WordPress Platform

  1. Research Cache Exclusions: Identify which URLs must be excluded from the cache for your specific platform
  2. Identify Cookie Exclusions: Determine which cookies need to be excluded to maintain functionality
  3. Test Thoroughly: Always test your site after implementing caching to ensure all dynamic features work correctly
  4. Monitor Performance: Use tools to monitor cache hit rates and overall site performance
  5. Regular Maintenance: Periodically review and update cache exclusions as your site evolves

Common Exclusions for Different Platforms

Platform URL Exclusions Cookie Exclusions
WooCommerce /cart/, /checkout/, /my-account/ woocommerce_cart_hash, woocommerce_items_in_cart
bbPress /forums/, /topics/ bbpress_* cookies
BuddyPress /members/, /activity/ bp-* cookies
Custom Membership Custom dashboard URLs Platform-specific session cookies
Pro Tip: Always consult the official documentation of your specific platform or plugin for the most accurate and up-to-date caching exclusion requirements.

Troubleshooting Common Issues

Issue 1: Shopping Cart Not Updating

  • Cause: Cart cookies are being cached
  • Solution: Verify that woocommerce_cart_hash and woocommerce_items_in_cart are in the Rejected Cookies list

Issue 2: User Login Issues

  • Cause: Login pages or authentication cookies are being cached
  • Solution: Ensure /wp-login.php is excluded and wordpress_logged_in cookies are rejected

Issue 3: Redis Connection Failed

  • Cause: Redis server not running or misconfigured
  • Solution: Check Redis status with sudo systemctl status redis-server

Issue 4: NGINX Configuration Errors

  • Cause: Syntax errors in server block or include files
  • Solution: Run sudo nginx -t to identify and fix syntax errors

Summary and Next Steps

Congratulations! You have successfully configured caching for a dynamic WordPress site with WooCommerce support.

What You've Accomplished

  • Configured NGINX server block for WP Super Cache
  • Installed and configured WP Super Cache plugin
  • Set up proper cache exclusions for WooCommerce
  • Configured Redis Object Cache with session exclusions
  • Learned the proper procedure for uninstalling caching plugins

Next Steps

  1. Monitor your site's performance and cache hit rates
  2. Consider implementing CSS/JS minification and concatenation
  3. Set up regular cache clearing schedules
  4. Test your site thoroughly, especially dynamic features
  5. Document your specific configuration for future reference
Remember: Caching is an ongoing process. As your site grows and changes, you may need to adjust your cache exclusions and configurations accordingly.