Nginx has a built-in FastCGI cache, which acts as a reverse proxy cache at the webserver layer. The Cache Sniper for Nginx WordPress plugin lets you purge this cache from within WordPress. Here are some key features:
- Purge the entire cache from the menu bar
- Manually purge individual pages
- Manually purge homepage cache
- Configure pages to purge automatically when updated
- Configure pages to purge automatically when comments are created/updated/deleted.
- Configure Settings via WP CLI
For more info on using this plugin with a pre-configured Nginx stack running in AWS, follow this
link.
- Upload the plugin files to the
/wp-content/plugins/snipe-nginx-cache
directory, or install the plugin through the WordPress plugins screen directly.
- Activate the plugin through the Plugins screen in WordPress
- Go to Tools -> Nginx Cache Sniper to configure the plugin
Usage
- Clear the entire cache by going to the Nginx Cache Sniper drop-down in the top Menu bar, and click Clear entire cache.
- Clear the homepage cache by going to the Nginx Cache Sniper drop-down in the top Menu bar, and click Clear homepage cache.
- To clear the cache for an individual Post (or Page), click on Clear cache for this page, either on the All Posts or Post detail pages.
- When configured to do so, you can purge the cache for a Post (or Page) by updating it.
- When configured to do so, you can purge the cache for a Post (or Page) where a comment was created/updated/deleted.
Configuration Settings
Cache Sniper for Nginx comes with the following settings:
- Cache Path: This is the filesystem path where the FastCGI cache is stored on-disk. Set this to the value you used for
fastcgi_cache_path
from your Nginx configuration. Note: Nginx needs read/write access to this location.
- Cache Levels: This sets up a directory hierarchy under the cache path. Set this to the value you used for
levels
from your Nginx configuration. For example: fastcgi_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=CACHE:100m;
- Automatically clear page cache on content update: Check this box to automatically purge the cache when a page is updated. This only purges the updated page -- it does not clear the entire cache.
- Automatically clear page cache on comment: Check this box to automatically purge the cache when a comment is created/updated/deleted. This only purges the cache of the page where the comment resides -- it does not clear the entire cache.
- Automatically clear homepage cache on content update: Check this box to automatically purge the homepage cache when a page is updated. This only purges the homepage -- it does not clear the entire cache or the cache of the page where the content resides.
- Automatically clear homepage cache on comment: Check this box to automatically purge the the homepage cache when a comment is created/updated/deleted. This only purges the cache of the homepage -- it does not clear the entire cache or the cache of the page where the content resides.
Configuration via WP CLI
For those scripting out infrastructure, Cache Sniper for Nginx can be configured via WP CLI:
wp plugin activate cache-sniper-nginx
wp option add nginx_cache_sniper_path '/var/lib/nginx/cache'
wp option add nginx_cache_sniper_levels '1:2'
wp option add nginx_cache_sniper_auto_clear 1
wp option add nginx_cache_sniper_auto_clear_comments 1
wp option add nginx_cache_sniper_auto_clear_home_page 1
wp option add nginx_cache_sniper_auto_clear_home_page_comments 1
For instructions on setting up FastCGI caching with Nginx, refer to this
Digital Ocean blog post.
Server-side configuration
There are a few things that need to be configured on the server in order for this plugin to work.
- Be sure to set
$scheme$request_method$host$request_uri
for fastcgi_cache_key
. For example: fastcgi_cache_key "$scheme$request_method$host$request_uri";
- The Linux account running Nginx needs read-write permissions to the cache path on disk.