srcache_max_expire

The `srcache_max_expire` directive sets the maximum time a cached item can remain valid in the NGINX subrequest-based caching system.

Syntaxsrcache_max_expire time;
Defaultnone
Contexthttp, server, location, if in location
Arguments1

Description

The srcache_max_expire directive is utilized in the NGINX configuration to control the upper limit of the cache expiration time for items stored in the transparent subrequest-based caching mechanism provided by the ngx_srcache module. This directive is particularly useful in scenarios where the server-side response caching needs to be finely tuned based on certain conditions.

When a cached item is stored, its expiration can often be set dynamically using variables or can follow certain caching rules defined by other directives such as srcache_store. The srcache_max_expire directive provides a definitive ceiling for this expiration time, ensuring that items cannot linger in the cache indefinitely beyond the time specified by this directive. This helps in optimizing the caching behavior, ensuring that stale data is not served to clients indefinitely, thus maintaining data freshness.

The parameter for this directive consists of a time value, which can be specified in various formats such as seconds, minutes, or hours (e.g., 30s, 5m, 1h). The exact combination and type of time values can be crucial, especially when working with high-availability systems where cache staleness might impact application performance. By defining this directive at the server or location level, it allows for context-specific caching strategies across different endpoints.

Config Example

location /cache {
    srcache_fetch my_cache;
    srcache_store my_cache;
    srcache_max_expire 10m;
}

Ensure that the value specified is not set to a negative duration, as this may cause caching to behave unpredictably.

If set too high without proper cache invalidation strategies, this may lead to serving stale content to clients.

← Back to all directives