This plugin hasn’t been tested with the latest 3 major releases of WordPress. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

Cache Sniper for Nginx

Description

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.

Screenshots

  • screenshot-1.png

Installation

  1. Upload the plugin files to the /wp-content/plugins/snipe-nginx-cache directory, or install the plugin through the WordPress plugins screen directly.
  2. Activate the plugin through the Plugins screen in WordPress
  3. Go to Tools -> Nginx Cache Sniper to configure the plugin

Usage

  1. Clear the entire cache by going to the Nginx Cache Sniper drop-down in the top Menu bar, and click Clear entire cache.
  2. Clear the homepage cache by going to the Nginx Cache Sniper drop-down in the top Menu bar, and click Clear homepage cache.
  3. 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.
  4. When configured to do so, you can purge the cache for a Post (or Page) by updating it.
  5. 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:

  1. 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.
  2. 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;
  3. 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.
  4. 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.
  5. 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.
  6. 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:

  1. wp plugin activate cache-sniper-nginx
  2. wp option add nginx_cache_sniper_path '/var/lib/nginx/cache'
  3. wp option add nginx_cache_sniper_levels '1:2'
  4. wp option add nginx_cache_sniper_auto_clear 1
  5. wp option add nginx_cache_sniper_auto_clear_comments 1
  6. wp option add nginx_cache_sniper_auto_clear_home_page 1
  7. 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.

  1. 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";
  2. The Linux account running Nginx needs read-write permissions to the cache path on disk.

FAQ

Do I need to recompile Nginx to purge the cache?

No. Cache Sniper for Nginx works without relying on any custom Nginx modules. This means you can easily keep Nginx updated with your normal package manager.

Reviews

ጥሪ 26, 2020
I have try many popular plugins like rtcamp with nginx_purge_cache module or Nginx cache by Till Krüss. I found this is the combination of both popular plugin. I can define cache path which work with file system (I use bindfs mount for cache path). I really like to have this plugin improve as following 1. should be able to define 2 multiple cache path, I use both proxy_cache and fastcgi_cache and right now I only select 1 path to purge cache key. 2. should allow debug log to easier make sure the cache key was purge. 3. the admin bar purge button should be fix, I can’t see the response action after click to purge, event I can see the cache key was clear in file system. 4. add purge cache page on current page that preview, instead of need to click update in admin page/post editor with 4 mentioned above, the plugin would be the best compare to other Regards,
ነሓሰ 15, 2018
Although this plugin doesn’t have many feature like Nginx Helper and Nginx Cache Controller, Cache Sniper for Nginx was the only plugin which working properly on my server setup (FEMP-FreeBSD 11.2-RELEASE, Nginx 1.15.2, MariaDB 10.2.16, and PHP 7.2.7). Great job, developers!
Read all 5 reviews

Contributors & Developers

“Cache Sniper for Nginx” is open source software. The following people have contributed to this plugin.

Contributors

Changelog

1.0.4.2

  • Fixed a bug that caused errors on post/page delete.

1.0.4.1

  • Fixed a bug that caused wp_insert_comment to fail.

1.0.4

  • Automatically clearing the homepage cache on content create/update/delete.
  • Manually clearing the homepage cache from the admin menu bar.
  • Clearing post/page cache when inserting a comment into the database using wp_insert_comment.

1.0.3.1

  • Clearing entire cache removes contents of the fastcgi_cache_path folder without deleting the folder itself.

1.0.3

  • Added cache levels configuration.

1.0.2

  • Fixed a bug that caused cache_actions.js file not to load.

1.0.1

  • Added support for page cache invalidation on comment create/udpate/delete.

1.0.0

  • First version, hope you like it!