srcache_store_no_cache

The `srcache_store_no_cache` directive instructs NGINX to prevent storing responses in the cache when a request contains specific headers indicating no-cache requirements.

Syntaxsrcache_store_no_cache on | off;
Defaultoff
Contexthttp, server, location
Argumentsflag

Description

The srcache_store_no_cache directive is a flag that enables NGINX to recognize when a response should not be cached based on the presence of certain Cache-Control, Pragma, or Expires headers in the request. When this directive is set to on, it checks incoming requests for headers that signal 'no-cache' conditions and subsequently marks the responses as non-cacheable, thereby ensuring that the objects will not be stored in the cache.

This directive can be used within various contexts such as http, server, and location, allowing for fine-grained control over caching behavior based on specific locations or server configurations. It is particularly useful in scenarios where sensitive or frequently changing data is being handled, such as user authentication or real-time updates, where caching responses could lead to serving stale or unauthorized information.

In practice, when srcache_store_no_cache is activated, it directly influences the cache management mechanism by checking for the defined 'no-cache' conditions and ensuring compliance with client request demands. This directive, therefore, plays a crucial role in maintaining the integrity and freshness of the responses served under conditional caching policies.

Config Example

location /api {
    srcache_store;
    srcache_store_no_cache on;
    proxy_pass http://backend;
}

Ensure that the directive is placed in the appropriate context (http, server, or location) to take effect.

Setting this directive without correctly handling cache headers in the application can lead to unintended cache misses or performance degradation.

Remember that this directive only functions when srcache_store is configured properly; otherwise, its effect may not be noticeable.

← Back to all directives