fastcgi_cache_min_uses

Sets the minimum number of uses before a response is cached in FastCGI cache.

Syntaxfastcgi_cache_min_uses number;
Default1
Contexthttp, server, location
Arguments1

Description

The fastcgi_cache_min_uses directive specifies the minimum number of identical requests that need to be made for a particular URI before its response will be cached. This can be particularly useful to avoid caching responses for low-traffic endpoints, ensuring that only commonly accessed content is stored in the cache. The value set for this directive should be a positive integer, as it indicates how many times a request for the same resource must be received before considering caching the response.

When the number of requests for a specific URI meets or exceeds the number defined by fastcgi_cache_min_uses, the cache mechanism is triggered for that response. This helps in optimizing the caching mechanism by preventing infrequent or irrelevant responses from occupying cache space. The directive can be set within http, server, or location contexts, allowing for granular control depending on application needs.

By minimizing potential cache pollution from seldom-accessed URIs, you can enhance the performance of your application as well as the efficiency of your cache storage. This is especially beneficial in scenarios involving dynamic content where some responses should not be cached unless they are frequently requested.

Config Example

http {
    fastcgi_cache_path /path/to/cache levels=1:2 keys_zone=my_cache:10m;
    server {
        location /api {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_cache my_cache;
            fastcgi_cache_min_uses 5;
        }
    }
}

Setting the value too high may lead to underutilization of the cache, as infrequent requests may not be cached at all.

Make sure that your backend is capable of handling the volume of requests if caching is disabled for low-use URIs.

Ensure that caching is enabled to take effect; otherwise, this directive has no effect.

← Back to all directives