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.
- 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
Step 1: Configure NGINX Server Block
1Navigate to NGINX Configuration Directory
2Open Your Site's Server Block File
3View WP Super Cache Excludes File
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
Step 2: Install and Configure WP Super Cache Plugin
1Install the Plugin
- Open your WordPress Dashboard
- Navigate to Plugins → Add New Plugin
- Search for "WP Super Cache"
- Click Install Now
- Click Activate
2Initial Configuration
- Go to Settings → WP Super Cache
- Click Caching On
- Click Update Status
- Click Test Cache to verify functionality
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
4Preload Configuration
- Go to the Preload tab
- Enable preload mode
- Enable both preload options
- Click Save Settings
5Debug Settings
- Go to the Debug tab
- Ensure Cache Status Messages is enabled
- Click Save Settings
Step 3: Configure WooCommerce Cache Exclusions
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/
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]
| 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
2Edit wp-config.php File
3Add WP Cache Key Salt
Scroll to the salt section and add the following constant:
define('WP_CACHE_KEY_SALT', 'example.com');
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');
5Save and Reload PHP-FPM
Step 5: Install and Configure Redis Object Cache Plugin
1Install Redis Object Cache Plugin
- Navigate to Plugins → Add New Plugin
- Search for "Redis Object Cache"
- Click Install Now
- Click Activate
2Enable Object Cache
- Go to Settings → Redis
- Status will show "Not Enabled"
- 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
Cache Exclusion Flow for WooCommerce
Step 6: Additional Optimizations
CSS and JavaScript Minification
For further optimization, install a minification plugin:
- Navigate to Plugins → Add New Plugin
- Search for a minification plugin (e.g., "Autoptimize")
- Install and configure according to your needs
Uninstalling WP Super Cache and Redis Object Cache
1Deactivate Redis Object Cache Plugin
- Go to Plugins → Installed Plugins
- Find "Redis Object Cache"
- Click Deactivate
- Click Delete
2Clean Up 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
4Disable WP Super Cache
- Go to Settings → WP Super Cache
- Click Turn Off Caching
- Click Update Status
- Click Clear Cache
5Deactivate and Delete WP Super Cache
- Go to Plugins → Installed Plugins
- Find "WP Super Cache"
- Click Deactivate
- Click Delete
6Update NGINX Server Block
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
Best Practices and Recommendations
For Any Dynamic WordPress Platform
- Research Cache Exclusions: Identify which URLs must be excluded from the cache for your specific platform
- Identify Cookie Exclusions: Determine which cookies need to be excluded to maintain functionality
- Test Thoroughly: Always test your site after implementing caching to ensure all dynamic features work correctly
- Monitor Performance: Use tools to monitor cache hit rates and overall site performance
- 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 |
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 -tto identify and fix syntax errors
Summary and Next Steps
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
- Monitor your site's performance and cache hit rates
- Consider implementing CSS/JS minification and concatenation
- Set up regular cache clearing schedules
- Test your site thoroughly, especially dynamic features
- Document your specific configuration for future reference