proxy_cache_path

The `proxy_cache_path` directive sets the path for storing cached responses when using the NGINX proxy caching functionality. — NGINX HTTP Core

proxy_cache_path
http
Синтаксисproxy_cache_path path [levels=levels] [keys_zone=name:size] [inactive=time] [max_size=size] [use_temp_path=on|off];
По умолчаниюnone
Контекстhttp
МодульNGINX HTTP Core
Аргументы2+

Описание

The `proxy_cache_path` directive in NGINX defines a specific path on the filesystem where cached data will be stored. This directive must be specified in the http context and can take several parameters that determine how the caching system manages and stores the cached data. The parameters for `proxy_cache_path` include the path to the cache directory, the levels of subdirectories for the cache, the key zone for managing the cache, and optional parameters such as `inactive` that define how long cached items should be retained before being considered stale. By specifying the levels for subdirectories, NGINX can efficiently manage the storage space used for caching, which is crucial for performance in high-traffic environments. When a cached response is requested, NGINX checks in the specified cache path to see if the response is already cached; if so, it serves the cached content directly, bypassing the need for an upstream request. This can significantly reduce latency and load on backend servers while improving the overall response time to clients.

Пример конфига

http {
    proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=my_cache:10m max_size=1g inactive=60m;
    server {
        location / {
            proxy_pass http://backend;
            proxy_cache my_cache;
        }
    }
}

Ensure that the specified cache path exists and is writable by the NGINX worker process.

Be cautious with cache size limits, as exceeding `max_size` can lead to unexpected cache evictions.

Using insufficient levels in the cache path can lead to performance degradation due to excessive file I/O.