uwsgi_cache_purge

The `uwsgi_cache_purge` directive allows purging cached responses from the uWSGI cache based on specified keys.

Syntaxuwsgi_cache_purge zone_name key;
Defaultnone
Contexthttp, server, location
Arguments1+

Description

The uwsgi_cache_purge directive is part of the NGINX Cache Purge module, enabling you to remove specific cached responses from the uWSGI cache system. This directive can be configured in the http, server, or location contexts and requires at least one argument: the cache zone name and a key that uniquely identifies the cached content. When a purge request is made, NGINX looks for cached entries matching the provided key and removes them, thus ensuring that the next request for that key retrieves fresh content from the upstream server instead of stale cached data.

This directive follows a similar syntax pattern to other cache purge directives in NGINX, such as proxy_cache_purge and fastcgi_cache_purge. Users can specify allowed methods for purging, access control by IP address or subnet, and whether to purge all cache items. To perform a purge operation, the request typically should have the appropriate HTTP method specified, which must match the method allowed in the configuration for the purge directive. Furthermore, you can also define the response type for the purge operation, which can be formatted as HTML, XML, JSON, or plain text, depending on how you wish to report the outcome of the purge operation.

Config Example

location /purge {
    uwsgi_cache_purge my_cache $uri;
    allow 192.168.1.0/24;  # Allow purge from this subnet
    deny all;  # Deny all others
}

Ensure the caching layer is properly configured to support purging; otherwise, it will not work as expected.

When purging with partial keys (using asterisk), make sure the asterisk is at the end of the key only; this is critical for proper matching.

Access control (IP allow/deny) should be set carefully to avoid unintentional purging of cache by unauthorized users.

← Back to all directives