Caching

Cache Purge

Flush the exact cache entry you want. Not the whole cache.

nginx-module-cache-purge

Install

You'll need nginx from nginx.org configured first. These packages won't load on the distro nginx.

Add the Blendbyte repository if you haven't already:

Add Blendbyte repository
sudo install -d -m 0755 /etc/apt/keyrings

curl -fsSL https://apt.blendbyte.net/nginx/blendbyte-archive-keyring.gpg \
  | sudo tee /etc/apt/keyrings/blendbyte.gpg >/dev/null

echo "deb [signed-by=/etc/apt/keyrings/blendbyte.gpg] https://apt.blendbyte.net/nginx $(lsb_release -cs) main" \
  | sudo tee /etc/apt/sources.list.d/blendbyte.list

sudo apt update

Then install this module:

Install nginx-module-cache-purge
$ sudo apt install nginx-module-cache-purge

Most modules auto-enable on install. If yours didn't:

Enable module manually (if needed)
$ sudo ln -s /etc/nginx/modules-available/50-mod-cache-purge.conf \
  /etc/nginx/modules-enabled/
$ sudo nginx -t && sudo systemctl reload nginx

What it does

Nginx's built-in caching gives you two options: wait for TTL, or nuke everything. Cache Purge adds a third: just remove the one entry you want gone. Hit a purge endpoint and nginx drops the matching cache entry immediately, nothing else touched. Works with proxy_cache (reverse proxy) and fastcgi_cache (PHP-FPM). The usual pattern is a restricted purge endpoint your CMS, deploy pipeline, or CDN webhook calls on content change. Cache entries are matched by cache key, which typically maps directly to URL. Long TTLs with instant on-demand invalidation. That's the setup most caching configs actually want.

When to use it

  • Instantly invalidate CMS content on publish without flushing unrelated cache
  • Integrate with deployment pipelines to purge affected URLs on release
  • Use long TTLs with selective purge instead of short TTLs as a workaround
  • Cache invalidation APIs for headless CMS and Jamstack setups
  • Purge fastcgi_cache entries from PHP application hooks

Configuration

A starting point. Adjust to taste.

nginx.conf example
proxy_cache_path /var/cache/nginx
                 levels=1:2
                 keys_zone=main_cache:10m
                 max_size=1g;

server {
  location / {
    proxy_cache       main_cache;
    proxy_cache_valid 200 7d;
    proxy_pass        http://backend;
  }

  # Purge endpoint (restrict by IP in production)
  location ~ /purge(/.*) {
    allow  127.0.0.1;
    deny   all;
    proxy_cache_purge main_cache "$scheme$request_method$host$1";
  }
}

Replacing a Sury package?

This replaces libnginx-mod-http-cache-purge from the old Sury nginx repository. The package declares Replaces and Conflicts so apt handles the swap in one transaction. No manual cleanup needed.

Drop-in replacement
# If you were using Sury, this upgrades in place:
sudo apt install nginx-module-cache-purge

See the full migration guide for the complete Sury-to-Blendbyte migration steps.

Upstream project

We package this from the upstream open-source project. If it's a bug in the module itself (not in our packaging), report it upstream.

https://github.com/FRiCKLE/ngx_cache_purge ↗

← All modules