slowfs_cache_valid

The `slowfs_cache_valid` directive controls the duration for which cached files are considered valid based on HTTP response codes.

Syntaxslowfs_cache_valid [reply_code] time;
Defaultnone
Contexthttp, server, location
Arguments1+

Description

The slowfs_cache_valid directive is used in the NGINX SlowFS Cache Module to specify the time for which the cached responses will be considered valid after they are stored. This directive accepts one or more response codes as arguments, each followed by a time duration. When specified, NGINX will serve cached content for the defined duration whenever it encounters the specified response codes. This directive is crucial for managing cached static files from slower filesystems and ensuring that stale content is not served too long.

For example, if you set slowfs_cache_valid 200 1h;, it means that any successful responses with a 200 status will remain valid in cache for one hour. If a file is requested after the cache duration has expired, NGINX will fetch a fresh copy. It is also possible to define multiple response codes with different durations, such as slowfs_cache_valid 200 1h 404 10m;, which caches 200 for one hour and 404 errors for ten minutes. This flexibility helps optimize caching strategies based on the behavior of your static files.

Overall, slowfs_cache_valid enhances the efficiency of content delivery by configuring the timing of cached responses, making it easier to balance performance and content accuracy in an NGINX server environment.

Config Example

location /images/ {
    slowfs_cache valid_cache;
    slowfs_cache_valid 200 1h;
    slowfs_cache_valid 404 10m;
    root /data/images;
}

Ensure that the specified time is appropriate for the content type to avoid serving stale files.

When using multiple status codes, ensure proper separation between the entries to prevent misconfigurations.

← Back to all directives