apache / trafficserver

Apache Traffic Serverâ„¢ is a fast, scalable and extensible HTTP/1.1 and HTTP/2 compliant caching proxy server.
https://trafficserver.apache.org/
Apache License 2.0
1.82k stars 806 forks source link

Negative Response Caching with Proxy.config.http.negative_caching_lifetime vs TTL-in-Cache #11854

Open incheoloh opened 1 week ago

incheoloh commented 1 week ago

cache.config

url_regex=.*    ttl-in-cache=20s

records.yaml

records:
  http:
    negative_caching_enabled: 1
    negative_caching_lifetime: 5

ttl-in-cache in cache.config sets a default TTL, applying this duration to cached responses regardless of the response code. proxy.config.http.negative_caching_lifetime in records.yaml is intended to set the TTL for negative responses (e.g., 403, 404). However, if ttl-in-cache is defined in cache.config, it takes precedence and applies a TTL of 20 seconds to all responses, including 403.

Is there any way to use the value set by proxy.config.http.negative_caching_lifetime instead of the ttl set by ttl-in-cache for negative responses?

incheoloh commented 1 week ago

The following configuration works as I wanted it to. It would be better if there was a secondary specification called 'status' in the cache.config file. (e.g dest_domain=example.com status=403 ttl-in-cache=60s)

If the default TTL is set to 1 day and negative response is set to 60 seconds Cache-Control and Cache.config are not configured.

records.yaml


proxy.config.http.cache.heuristic_min_lifetime : 86400 
proxy.config.http.cache.heuristic_max_lifetime : 86400

proxy.config.http.negative_caching_enabled : 1
proxy.config.http.negative_caching_lifetime : 60