Skip to content

feat(ml-api): add reload-aware /predict response cache - #1019

Open
pavsoss wants to merge 2 commits into
Userunknown84:mainfrom
pavsoss:feat/1008-predict-cache
Open

feat(ml-api): add reload-aware /predict response cache#1019
pavsoss wants to merge 2 commits into
Userunknown84:mainfrom
pavsoss:feat/1008-predict-cache

Conversation

@pavsoss

@pavsoss pavsoss commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

/predict re-ran inference for every request, including identical repeats. This adds an in-process cache.

  • A thread-safe TTL + LRU cache keyed by sha256(normalized_text) combined with the serving model version.
  • /predict returns cached bodies on a hit and sets X-Cache: HIT|MISS; callers can bypass with Cache-Control: no-cache or ?fresh=1.
  • A public GET /cache-stats reports hits/misses/size.

Why it's safe

Namespacing the key by the serving version means a model hot-swap invalidates the cache automatically — no stale outputs. Response bodies are unchanged; X-Cache is additive.

Test plan

Hit/miss behavior, TTL expiry, invalidation across a version bump, and the bypass header/param.

Closes #1008

@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

@pavsoss is attempting to deploy a commit to the Aditya Sharma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Userunknown84 Userunknown84 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Merge Conflict

@pavsoss
pavsoss requested a review from Userunknown84 July 29, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Content-addressed /predict response cache (TTL + LRU) with reload-aware invalidation

2 participants