Add entry-status and function-entries for cache introspection - #2
Conversation
Callers (e.g. Clerk notebooks) need a way to show freshness metadata for cache entries without taking a raw JDBC dependency or duplicating the serialization/key logic. entry-status looks up a single entry by cached-fn + args; function-entries returns all entries for a cached-fn. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e56fdbd99a
ℹ️ 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".
| - :cold? true if past TTL (evictable if not re-hit soon) | ||
| - :stale? true if past max-age (will be evicted unconditionally)" | ||
| [cached-fn cache-args] | ||
| (let [{:keys [read-conn func-name args-cache-key ttl max-age]} (meta cached-fn) |
There was a problem hiding this comment.
Compute cold/stale flags from each row's TTL values
entry-status (and similarly function-entries) derives ttl/max-age from cached-fn metadata instead of the row being inspected, so :cold? and :stale? can be wrong when the same cache DB contains entries written under older settings (for example after deploying with new TTLs). The cache’s read/expiry logic uses per-row :ttl/:max-age, so these introspection flags can disagree with actual eviction behavior; selecting :ttl and :max-age from the row would keep status reporting accurate.
Useful? React with 👍 / 👎.
Instead of reimplementing the cold/stale predicates in pure Clojure, delegate to the existing maint/cold? and maint/stale? HoneySQL expressions so SQLite computes them. Also unprivates maint/maybe-inst which is shared by both namespaces. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Also refactors the two fns to share coerce-status-row and status-base-query helpers, fixes defn- to ^:private per codebase style, and exposes base-cached-fn in the test harness context so introspection fns (which read metadata) can be tested cleanly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Code-review note from a consumer:
Different serialized bytes ⇒ Doesn't affect my use case — I'm passing |
Make entry-status variadic (& cache-args) so the args list arrives as the same ISeq type that cached uses, eliminating the seq conversion that mapped [] to nil and caused a serialization mismatch for 0-arity cached functions. Adds a targeted 0-arity test and a generative property that verifies entry-status finds the row for any arg list. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Above comment has been addressed. |
Summary
entry-status— looks up a single cache entry by cached-fn + args, returning:created-at,:last-hit,:hits,:cold?,:stale?(ornilif no row)function-entries— returns the same fields for every live entry belonging to a cached-fn, plus deserialized:argsfor table displayargs-cache-key+ serialization path the cache already uses internally, so callers don't duplicate that logic or touch the schema directlyTest plan
bb testpasses (258 assertions, 0 failures)entry-statusreturnsnilbefore the cached fn is called, a populated map after:cold?/:stale?reflect the configured TTL / max-age correctlyfunction-entriesreturns one entry per distinct arg set🤖 Generated with Claude Code