Skip to content

feat(ads-client): respect server max-age in cache TTL resolution#7344

Draft
Almaju wants to merge 6 commits intomozilla:mainfrom
Almaju:ac-103-cache-ttl-strategy
Draft

feat(ads-client): respect server max-age in cache TTL resolution#7344
Almaju wants to merge 6 commits intomozilla:mainfrom
Almaju:ac-103-cache-ttl-strategy

Conversation

@Almaju
Copy link
Copy Markdown
Contributor

@Almaju Almaju commented Apr 29, 2026

Resolve effective TTL by priority — explicit per-request TTL wins, otherwise the response's Cache-Control: max-age is used, otherwise the configured default_ttl. Result is capped at 7 days for safety.

Previously the layer took the min of all three, which collapsed to the short default_ttl in practice and ignored the server's max-age signal.

AC-103

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

Almaju added 6 commits April 29, 2026 15:49
Resolve effective TTL by priority — explicit per-request TTL wins,
otherwise the response's Cache-Control: max-age is used, otherwise the
configured default_ttl. Result is capped at 7 days for safety.

Previously the layer took the min of all three, which collapsed to the
short default_ttl in practice and ignored the server's max-age signal.

AC-103
Move the priority-chain TTL resolution out of `CacheControl::effective_ttl`
into a dedicated `ttl` module with a `resolve_ttl(TtlInputs { ... })`
free function. The named-fields struct labels each input at the call
site, making the source of every value (caller / server / config) clear.

`CacheControl` is now back to its original job — parsing the response's
Cache-Control header — and exposes `max_age_duration()` for callers that
want a `Duration` instead of raw seconds.
Move the TTL resolution from a free function into an inherent method on
TtlInputs, and drop pub(super) restrictions in favor of plain pub
(visibility is already bounded by the private ttl module).
Drop the shared DEFAULT_TTL/MIN_TTL/MAX_TTL constants and the builder's
TTL/max-size range validation. The http_cache module now trusts whatever
the caller configures and no longer caps server-supplied max-age values.

This keeps http_cache standalone and free of policy decisions; deciding
what counts as a reasonable TTL or cache size is the consumer's job.

Drops the InvalidTtl and InvalidMaxSize variants from
HttpCacheBuilderError as a result.
The struct represents the concept being computed (the effective TTL),
not a parameter pack — `EffectiveTtl { ... }.resolve()` reads more
naturally at the call site.
Roll back the bounds-removal changes from this branch. Cache size and
TTL validation in HttpCacheBuilder, the InvalidMaxSize/InvalidTtl error
variants, and their telemetry codes are restored to match main.

Those changes are out of scope for AC-103 (the priority-order TTL
resolution) and should be revisited separately.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant