Repository navigation
feat(api): cache reference data in memory for 24 hours - #132
Merged
Merged
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 50 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
🦋 Changeset detectedLatest commit: 0bc01bf The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Add ResponseCache (TTL + LRU, in-flight dedupe, errors never cached) and an opt-in cacheTtlMs option on SimapClient.get(). The cantons, institutions and CPV/BKP/NPK/OAG code tools now use a 24 h TTL, so repeated lookups skip the network and the 60 req/min rate limiter. Tender and organization lookups stay live. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mathieumaf
force-pushed
the
feat/cache-reference-data
branch
from
November 5, 2026 10:19
0168baa to
0bc01bf
Compare
This was referenced Nov 5, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Cantons, institutions and the CPV/BKP/NPK/OAG nomenclatures almost never change, yet every lookup hit simap.ch and used a slot of the 60 requests/minute budget. Models often explore codes and come back to them before searching, so these calls repeat a lot within a session.
What
src/api/response-cache.ts(new):ResponseCache, an in-memory cache with a per-entry TTL, capped at 500 entries (least recently used evicted first). It stores the pending promise, so concurrent identical requests share one upstream call. Rejected requests, including Zod validation failures, are evicted and never cached.SimapClient.get(): new opt-incacheTtlMsoption, keyed on the full URL (query params included). A cache hit skips the rate limiter and the network and is logged asGET <endpoint> (cache hit). NewREFERENCE_DATA_TTL_MSconstant (24 h).SimapClienttakes the cache as an optional 4th constructor argument, afterretry.list_cantons,list_institutions,search_{cpv,bkp,npk,oag}_codes,browse_{cpv,bkp,npk,oag}_tree.search_tenders,get_tender_details,search_proc_offices,get_publication_history(live data).ARCHITECTURE.mdandCLAUDE.mdupdated. Changeset:patch, since tools, parameters and output are unchanged.Trade-off
Reference data can be up to 24 h stale. The cache lives in process memory only and is cleared when the server restarts.
Tests
tests/api/response-cache.test.ts: hit/miss, TTL expiry, LRU eviction, shared in-flight load, failures not cached,clear().tests/api/client.test.ts: no caching withoutcacheTtlMs, caching keyed on params, API errors and schema failures not cached, no rate-limit slot used on a hit, cache-hit log line, successful result of a retried request cached once.npm run typecheck,npm run lint,npm run format:check,npm run buildandnpm test(364 tests, after rebasing on #130 and #131) pass locally.🤖 Generated with Claude Code