fastcgi_cache_purge
The fastcgi_cache_purge directive allows for the purging of cached content in FastCGI caches.
Description
The fastcgi_cache_purge directive, part of the NGINX Cache Purge module, enables administrators to remove specific entries from FastCGI caches based on cache keys. This is especially useful for dynamic content that may change frequently and needs to be refreshed in the cache without completely flushing the entire cache. The directive can be configured to operate in various contexts including http, server, and location, allowing for flexible application in different scopes of your NGINX configuration.
The syntax for the directive allows you to specify a method (GET or POST), whether all cache entries can be purged, and to restrict purging based on specific IP addresses or ranges. The caching mechanism allows for the use of wildcards in keys, enabling the removal of multiple related cache entries with a single request. For instance, sending a purge request for /page* would target all cached entries related to pages that start with /page. Utilizing this directive effectively requires careful consideration of access control, as inadvertently allowing purging can lead to unintended cache invalidation.
Moreover, the directive can return different types of responses (HTML, JSON, XML, or plain text) indicating the success or failure of the purge operation, configurable via the cache_purge_response_type directive. This helps in distinguishing the outcomes of operations better from an API or user interface perspective.
Config Example
http {
fastcgi_cache_purge on;
location /purgeme {
fastcgi_cache_purge fastcgi_cache_zone $request_uri;
}
}Make sure the IP address or range specified in 'from' is accurate; if incorrectly set, it may allow purges from unauthorized users.
Using a wildcard in the cache key may lead to unintended cache invalidation if not configured carefully.
Purging requires urgent attention to user permissions; unauthorized users should not have the ability to purge cache.