scgi_cache_bypass
The `scgi_cache_bypass` directive controls when to bypass the SCGI cache based on specified conditions. — NGINX HTTP Core
Описание
The `scgi_cache_bypass` directive is used to define conditions under which the SCGI cache should be bypassed for specific requests. It accepts one or more arguments that can utilize variables, such as headers or server variables, to determine whether the cache should be ignored. When the condition evaluates to a non-empty value, the response will not be served from the cache, and a new request will be sent to the upstream server instead. This can be particularly useful for dynamic content that should not be cached, ensuring that users receive the latest data. This directive works within the `http`, `server`, or `location` contexts, allowing for fine-grained control over caching behavior based on the application's needs. For instance, if you want to bypass the cache for requests that include a specific cookie or header, you can use this directive effectively to specify that condition. Bypassing the cache can also improve performance in scenarios where data changes frequently or is user-specific, preventing serving stale content. Users should be careful with overusing this directive, as excessive bypassing of the cache can lead to increased load on the upstream servers and potential performance degradation. This necessitates a careful balance between caching and real-time access requirements.
Пример конфига
location /api {
scgi_pass backend;
scgi_cache my_cache;
scgi_cache_bypass $http_cache_bypass;
}Using this directive without proper conditions can lead to unintended caching behavior.
If the bypass condition is always true, it negates the benefits of caching altogether.
Make sure to test the conditions in a production-like environment to avoid performance issues.