Skip to content

Add X-Cache HIT/MISS header to cached API responses - #604

Merged
bpepple merged 1 commit into
masterfrom
x-cache
Aug 20, 2026
Merged

Add X-Cache HIT/MISS header to cached API responses#604
bpepple merged 1 commit into
masterfrom
x-cache

Conversation

@bpepple

@bpepple bpepple commented Aug 20, 2026

Copy link
Copy Markdown
Member

Description

The Redis-backed response caching added in #603 had no way to confirm from outside the process whether a given response actually came from the cache or was recomputed — checking required either comparing response timings or inspecting Redis keys directly via redis-cli.

Every response that goes through cache.get()/cache.set()retrieve, list, issue_list-style detail actions, and PublisherViewSet.series_list — is now tagged with an X-Cache: HIT or X-Cache: MISS header via a shared _mark_cache_status() helper, so it's a plain curl away:

curl -sI -H "Authorization: Bearer <your-token>" https://metron.cloud/api/issue/1/ | grep -i x-cache

A viewset/action with caching disabled (Collection/PullList/WishList/ ReadingList — user-scoped, never cached) gets no header at all rather than a misleading MISS, so the header's presence also doubles as confirmation that caching applies to a given endpoint at all.

Test plan

  • Added tests covering all four cache-wrapping code paths (retrieve, list, issue_list action, publisher series_list), asserting MISS on first request and HIT on the immediate repeat.
  • Added a test confirming an uncached viewset gets no X-Cache header.
  • Full test suite passes.

@bpepple bpepple self-assigned this Aug 20, 2026
@bpepple bpepple added enhancement New feature or request api An API bug/feature labels Aug 20, 2026
@bpepple
bpepple merged commit 4ba7080 into master Aug 20, 2026
2 checks passed
@bpepple
bpepple deleted the x-cache branch August 20, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api An API bug/feature enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant