Skip to content

Add TTL-based cache expiration aligned to data release cadence#155

Open
ChrisPachulski wants to merge 1 commit intovirattt:mainfrom
ChrisPachulski:pr/cache-ttl-expiration
Open

Add TTL-based cache expiration aligned to data release cadence#155
ChrisPachulski wants to merge 1 commit intovirattt:mainfrom
ChrisPachulski:pr/cache-ttl-expiration

Conversation

@ChrisPachulski
Copy link

Motivation

The file cache currently has two gaps: most finance tools don't opt into caching
at all, and the ones that do (filing items, historical prices) cache entries
indefinitely with no expiration. This means the agent either re-fetches unchanged
data on every run or serves arbitrarily stale results.

This PR closes both gaps. Every finance tool now opts into caching with a TTL
aligned to how frequently the underlying data actually updates — so repeated
queries within a research session resolve instantly from disk, and stale entries
are automatically evicted once they've aged past their data's natural refresh
cycle.

A note on caching trade-offs

I realize more caching means fewer API calls, and fewer API calls means less
revenue. That's a real trade-off and I don't take it lightly. But from a pure
functionality standpoint, I couldn't justify not doing this — re-fetching
immutable SEC filings or unchanged quarterly financials on every run doesn't
serve the user, it just adds latency. The TTLs here are aligned to actual data
release cadences, so nothing goes stale silently, and users still hit the API
whenever the data has genuinely refreshed.

Changes

  • Cache entries now carry a per-entry TTL, checked on read. Expired entries are
    auto-removed.
  • Weekly (7d) — price snapshots, news, crypto snapshots
  • Monthly (30d) — analyst estimates, company facts
  • Quarterly (90d) — financial statements, SEC filings, insider trades,
    historical prices
  • Backward compatible — existing entries without a TTL fall back to the 7-day
    default.

Test plan

  • bun run typecheck passes
  • bun test passes — 5 new TTL tests + all existing tests unaffected
  • ~13 changed files, all cache-related

🤖 Generated with Claude Code

Cache entries now expire based on data mutability: weekly (7d) for
snapshots and news, monthly (30d) for estimates and company facts,
quarterly (90d) for financial statements, filings, and historical
prices. Existing entries without TTL fall back to the 7-day default.
Expired entries are auto-removed on read.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@virattt
Copy link
Owner

virattt commented Feb 17, 2026

Hey @ChrisPachulski - the lack of caching for the majority of the financial data endpoints is intentional. We want the freshest / most real-time data.

In your changes, you're suggesting that we cache price snapshot data for 1 week, which does not make sense.

Why would we cache the price of Apple stock for 1 week and treat it as the snapshot?

@ChrisPachulski
Copy link
Author

Fair point on price snapshots — I should have been clearer on the intent here. The caching isn't meant to serve week-old prices as current. It's to preserve a local historical reference so the agent can store snapshots for analysis, review, and cross-session comparison (e.g. "how has this moved since last session" or referencing earlier data points in a new chat) without re-fetching data it already pulled. The TTL is really an eviction policy, not a freshness guarantee.

Same logic applies to financial filings and statements — those are immutable once filed, so re-fetching them every call is pure latency with no upside.

Happy to revise the TTLs if the current windows don't feel right — or I can just leave it as-is if you'd prefer. Let me know.

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.

2 participants