srcache_default_expire
Sets the default expiration time for cached entries in the srcache module.
Description
The srcache_default_expire directive is used to specify the default time-to-live (TTL) for stored cached responses in the Transparent subrequest-based caching layout for NGINX locations. This directive plays a critical role in cache management, determining how long a cached entry remains valid before it has to be considered stale and subsequently refreshed. The expiration time applies to cache entries when no explicit expiration time is defined for individual cached items or when they are served without specific cache directives present.
To use srcache_default_expire, you need to specify a duration argument that follows the NGINX syntax for time values, such as 1m, 5h, or 24s. The expiration time set by this directive affects all caching behavior within the specific scope it's defined—in the http, server, location, and conditional if in location contexts. By setting a sensible default expiration time, you can balance between data freshness and reducing the load on the backend server by avoiding unnecessary repeated requests for the same resource.
This means if an entry is cached using this directive, it will not be re-fetched from the upstream source until the specified time has elapsed, making it a powerful tool for optimizing response times and server performance. However, it's important to set this time wisely based on how often the underlying data changes; too long could serve stale data, and too short might lead to excessive fetching.
Config Example
location /example {
srcache_default_expire 10m;
# Further configuration here
}The expiration time must be specified in a valid time format (e.g., 5m, 30s) and cannot be omitted.
If you set an expiration time that is too short, it may lead to frequent requests to the backend, negating the benefits of caching.
Remember that the directive only applies when no other specific expiration settings are defined.
Misconfigurations in the caching hierarchy can lead to either stale data being served or excessive resource usage.