nginx config. Does "proxycachevalid" accepts variables?
- User
nginx config. Does "proxy_cache_valid" accepts variables?
- Assistant
In NGINX, the directive
proxy_cache_validdoes not accept variables.The
proxy_cache_validdirective is used to define how long responses from the proxied server should be considered valid and stored in the cache. It requires fixed time values and optional status codes, but it does not support dynamic values or variables.Example of valid usage:
proxy_cache_valid 200 302 10m; proxy_cache_valid 404 1m;This means:
- Cache 200 and 302 responses for 10 minutes.
- Cache 404 responses for 1 minute.
❌ Invalid usage (does not work):
set $cache_time 10m; proxy_cache_valid 200 $cache_time; # This is invalidIf you need dynamic cache times based on request parameters or other variables, you would need to use different
locationblocks ormapdirectives to set different cache policies conditionally.Example using
map:map $arg_cache_time $cache_duration { default 10m; "short" 1m; "long" 1h; } # Then use the mapped value in a conditional location location / { proxy_cache_valid 200 302 10m; # Still must be static }But again, even with
map, you cannot pass a variable directly toproxy_cache_valid. You would need to define separate locations with different staticproxy_cache_validvalues if you want different caching behavior.In summary:
🔴 No,
proxy_cache_validdoes not accept variables.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.