Skip to content

fix: keep every cached bulk file until its ttl - #71

Merged
jm-rivera merged 2 commits into
mainfrom
fix/bulk-cache-keeps-every-file
Oct 21, 2026
Merged

jm-rivera merged 2 commits into
mainfrom
fix/bulk-cache-keeps-every-file

Conversation

@jm-rivera

@jm-rivera jm-rivera commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

CacheManager._evict_lru in src/oda_reader/_cache/manager.py kept the keep_n=2 most recently downloaded entries across the whole bulk cache. Each URL has one entry keyed on sha1(url), and a refetch overwrites that entry's file in place, so the eviction never removed an old version of anything. It removed other datasets. A pipeline that reads CRS, DAC1 and DAC2a downloaded all three again on every run, including the 1.18 GB CRS.parquet. Live checks against 1.11.3 confirmed it: cycling four DAC files, or the full, reduced and 2024 CRS files, re-streamed every one on the second pass.

_evict_lru and the keep_n argument are gone. The startup sweep, _evict_expired, deletes each entry whose age exceeds its own ttl_days, along with its file, and keeps the record when the file cannot be deleted, so the TTL is the one bound on what the cache holds. CacheEntry.ttl_days defaults to 90, up from 30. The ETag check catches a republish on any call, so the TTL only decides freshness when that check fails, and disk use grows with the number of distinct bulk files a user fetches. docs/docs/caching.md, src/oda_reader/_cache/README.md and the DAC1 and DAC2b docstrings describe the new rule. The version is 1.11.4.

Testing: uv run pytest passed (581 passed, 8 skipped). tests/cache/test_expiry_eviction.py replaces the LRU tests: four entries within their TTL all survive, an entry one day past its TTL is removed from disk and manifest while one a day short stays, and a failed unlink keeps the record so the next sweep removes it. All three fail against the previous manager.py. ruff check, ruff format --check and ty check pass. Against the live host, DAC1, DAC2b and the CRS 2024 file downloaded in one process and all three loaded from the cache in a second.

CacheManager kept the two most recently downloaded bulk files across
all datasets, so a pipeline using three or more downloaded every file
again on each run. Each URL has one entry and a refetch overwrites its
file, so the eviction only deleted files still in use. The startup
sweep now deletes entries past their own TTL, and the bulk TTL is 90
days.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T10:28:19.180372Z c2c90b5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c2c90b5320

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/oda_reader/_cache/manager.py
@jm-rivera
jm-rivera merged commit 9563013 into main Oct 21, 2026
10 checks passed
@jm-rivera
jm-rivera deleted the fix/bulk-cache-keeps-every-file branch October 21, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant