Skip to content

FEAT: Add Stale-While-Revalidate Mode To CacheRead #4

@MrEthical07

Description

@MrEthical07

Background:
Current cache behavior is strict hit or miss. There is no stale serving strategy during backend slowness.

Problem:
Without stale-while-revalidate, p95 and p99 can degrade sharply during transient backend latency spikes.

Scope:

  • Extend cache manager and CacheRead policy to support stale-while-revalidate behavior.
  • Keep authenticated-cache safety and vary-by requirements unchanged.
  • Update behavior docs in docs/cache-guide.md after implementation.

Tasks:

  • Add stale window and metadata handling in cache manager.
  • Add policy flow for stale serve with background refresh.
  • Add tests for stale hit, stale expired, refresh success, refresh failure.
  • Ensure observability labels distinguish stale serve vs normal hit.

Acceptance Criteria:

  • Stale responses can be served within configured stale window.
  • Background refresh does not break request path.
  • Authenticated cache invariants and validation rules are preserved.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions