Add percentage limit for stale cache age - #13547
Merged
Merged
Conversation
A fixed stale-age window can let short-lived cached responses remain usable for many times their original freshness lifetime. This makes serving stale content disproportionately risky for responses with a short max-age. This adds an optional percentage limit and applies the smaller of the percentage-based and absolute stale-age windows. The default keeps the existing behavior, while transaction overrides and supported scripting interfaces can opt in per use case. Fixes: apache#12252
serrislew
reviewed
Aug 18, 2026
The effects of zero and fractional-second percentage limits are not obvious. Operators could mistake zero for disabling stale responses or expect a nonzero percentage always to permit at least one stale second. This clarifies that zero leaves the absolute limit in control and that percentage windows use whole seconds rounded down, with concrete examples of both cases.
bneradt
force-pushed
the
max-stale-age-percent
branch
from
August 18, 2026 20:25
0bdc030 to
1855d19
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated no new comments.
Suppressed comments (4)
tests/gold_tests/cache/replay/max_stale_age_percent.replay.yaml:89
- To reduce timing sensitivity, widen the margin on the "within percentage limit" transaction by increasing the delay and updating the comment to match the configured percentage window.
# At five seconds old, the object is stale but remains within the two-second
# percentage stale window.
- client-request:
delay: 5s
method: "GET"
tests/gold_tests/cache/replay/max_stale_age_percent.replay.yaml:106
- Likewise, widen the margin on the "past percentage limit" transaction by increasing the delay and updating the comment to reflect the new percentage calculation.
# At eight seconds old, the object exceeds max-age (4 seconds) plus 50%
# (2 seconds), even though the absolute stale age limit is 100 seconds.
- client-request:
delay: 3s
method: "GET"
src/proxy/http/HttpTransact.cc:6413
get_max_age()returns -1 when neithers-maxagenormax-ageis present, but this value is still used inmax_age + max_stale_age. That effectively subtracts 1 second from the allowed stale window for responses withoutmax-age, which also contradicts the doc change that says those responses are controlled bymax_stale_agealone. Consider clamping themax_ageused for the age-sum to at least 0 before doing the comparison (keeping the percentage logic gated onmax_age >= 0).
// Negative age is overflow
if ((current_age < 0) || (current_age > max_age + max_stale_age)) {
TxnDbg(dbg_ctl_http_trans, "document age is too large %" PRId64, (int64_t)current_age);
tests/gold_tests/cache/replay/max_stale_age_percent.replay.yaml:53
- This replay test uses a 4s max-age with a 50% stale window and only 1s of headroom on the "should still be served stale" request (5s vs allowed 6s). That can be timing-sensitive in CI. Consider using a larger margin (e.g., 100% with adjusted delays) so the pass/fail cases are less likely to flap due to scheduling jitter.
This issue also appears in the following locations of the same file:
- line 85
- line 102
proxy.config.http.cache.max_stale_age: 100
proxy.config.http.cache.max_stale_age_percent: 50
proxy.config.http.parent_proxy.self_detect: 0
serrislew
approved these changes
Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A fixed stale-age window can let short-lived cached responses remain
usable for many times their original freshness lifetime. This makes
serving stale content disproportionately risky for responses with a
short max-age.
This adds an optional percentage limit and applies the smaller of the
percentage-based and absolute stale-age windows. The default keeps the
existing behavior, while transaction overrides and supported scripting
interfaces can opt in per use case.
Fixes: #12252