feat: opt-in in-memory package-insert cache (ADR-0011)#43
Merged
Conversation
Assisted-By: Claude <noreply@anthropic.com>
Separates network (bytes) from parse so the cache can store raw XML and re-parse on hit. check_insert_updates keeps using the parsed wrapper. Assisted-By: Claude <noreply@anthropic.com>
In-memory LRU-by-age cache of raw GetDrugDoc XML keyed by license code: TTL + entry/byte caps (oldest-first eviction), per-key herd lock with a lock-free fast path. Empty and unparseable results are never cached (no false 'not found'); periodic INFO stats rollup for tuning. Assisted-By: Claude <noreply@anthropic.com>
… (ADR-0011) Adds from_cache + cache_age_hours to the response; retrieved_at reports the real TFDA fetch time even on a hit. last_update_date is unaffected by caching. Assisted-By: Claude <noreply@anthropic.com>
… cache ADR-0011 -> Accepted. CHANGELOG, .env.example, README deployment note. Assisted-By: Claude <noreply@anthropic.com>
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.
Summary
Implements ADR-0011 — an opt-in, off-by-default, in-memory cache of raw
GetDrugDoc XML keyed by license code. Cuts repeat egress to
mcp.fda.gov.twfor the shared HTTP service (ADR-0010 Model B), where every clinician's
get_package_insertleaves through one IP. Individualuvxusers keep theADR-0009 live-fetch behaviour by default (cache off).
InsertCache(sources/insert/cache.py): stores raw XML bytes, re-parseson hit (one entry serves any
fields/response_format, robust to parserchanges). TTL + entry/byte caps with oldest-first eviction; per-license herd
lock with a lock-free fast path; periodic INFO stats rollup.
fetch_drug_insert_bytes(network→bytes) under the existingfetch_drug_insert(bytes→parsed).check_insert_updateskeeps the parsedpath and never touches the cache.
get_package_insertgainsfrom_cache+cache_age_hours;retrieved_atreports the real TFDA fetch time even on a hit;last_update_date(clinical currency) is unaffected by caching.
upstream blip cannot pin a false
INSERT_NOT_FOUNDfor the TTL.INSERT_CACHE_ENABLED(off),INSERT_CACHE_TTL_HOURS(6),INSERT_CACHE_MAX_ENTRIES(1000),INSERT_CACHE_MAX_MB(128).Deviation from ADR §3 phasing: both entry and byte caps ship together (the
byte counter is needed regardless, one eviction loop handles both, and the
Verification section tests the byte cap) — clarity over splitting.
Test Plan
ruff check .cleanpyright src— 0 errorspytest— 152 passed (+20 new), 8 integration/smoke deselected, ~1.7sfrom_cache,cache_age_hours)Assisted-By: Claude noreply@anthropic.com