cache-purge

Purge entries from proxy and FastCGI caches

dynamic moduleBSD-2-Clausesource

Overview

ngx_cache_purge adds cache purging to nginx. It deletes entries from the caches populated by the proxy, FastCGI, uWSGI, and SCGI modules, a capability the open source nginx core does not include.

A purge is triggered by an HTTP request whose computed cache key matches the entry to remove, usually via a dedicated location restricted to trusted addresses. Applications can then invalidate a stale page immediately instead of waiting for the cache entry to expire.

The module was written by Piotr Sikora at FRiCKLE and upstream marks it production ready. It is a common companion to WordPress and other CMS caching plugins.

Key directives

proxy_cache_purgeRemoves an entry from a proxy_cache zone whose key matches the given value.
fastcgi_cache_purgeRemoves an entry from a fastcgi_cache zone, the usual choice for PHP-FPM setups.
uwsgi_cache_purge / scgi_cache_purgeThe same purge support for caches filled by the uwsgi and scgi modules.
Access controlPurge endpoints are ordinary nginx locations, so allow and deny rules decide who may purge.

Example

nginx.conf
load_module modules/ngx_http_cache_purge_module.so; http { proxy_cache_path /var/cache/nginx/app keys_zone=app_cache:10m; server { location / { proxy_pass http://127.0.0.1:8080; proxy_cache app_cache; proxy_cache_key $uri$is_args$args; } location ~ /purge(/.*) { allow 127.0.0.1; deny all; proxy_cache_purge app_cache $1$is_args$args; } } }

Availability

Ships as a dynamic module in libnginx-mod-http-cache-purge, installed automatically with nginx-extras. The package drops a load_module config into /etc/nginx/modules-enabled/, so it loads on start.