Skip to content

Add percentage limit for stale cache age - #13547

Merged
bneradt merged 2 commits into
apache:masterfrom
bneradt:max-stale-age-percent
Aug 18, 2026
Merged

Add percentage limit for stale cache age#13547
bneradt merged 2 commits into
apache:masterfrom
bneradt:max-stale-age-percent

Conversation

@bneradt

@bneradt bneradt commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

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

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
Copilot AI lite review requested due to automatic review settings August 13, 2026 19:54
@bneradt bneradt added this to the 11.0.0 milestone Aug 13, 2026
@bneradt bneradt self-assigned this Aug 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings August 13, 2026 20:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bryancall
bryancall requested a review from serrislew August 17, 2026 22:03
Comment thread src/proxy/http/HttpTransact.cc
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.
Copilot AI review requested due to automatic review settings August 18, 2026 20:25
@bneradt
bneradt force-pushed the max-stale-age-percent branch from 0bdc030 to 1855d19 Compare August 18, 2026 20:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 neither s-maxage nor max-age is present, but this value is still used in max_age + max_stale_age. That effectively subtracts 1 second from the allowed stale window for responses without max-age, which also contradicts the doc change that says those responses are controlled by max_stale_age alone. Consider clamping the max_age used for the age-sum to at least 0 before doing the comparison (keeping the percentage logic gated on max_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

@bneradt
bneradt merged commit a2ea029 into apache:master Aug 18, 2026
15 checks passed
@bneradt
bneradt deleted the max-stale-age-percent branch August 18, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Add % max_stale_age config

3 participants