Skip to content

Add expire, a wrapper that gives entries a time to live - #9

Merged
floatdrop merged 2 commits into
mainfrom
expire
Nov 23, 2026
Merged

floatdrop merged 2 commits into
mainfrom
expire

Conversation

@floatdrop

Copy link
Copy Markdown
Owner

For v0.3.0.

  • expire. expire.Wrap(cache, ttl) gives the entries of any evict.Cache a time to live, and SetWithTTL one per entry.
    • An expired entry is a miss for Get, Peek, GetMany, Delete and All, but stays until it is evicted, set again, deleted or cleared.
    • Readers look at a copy of the time that one shared timer updates every 10 ms, and at the time itself within 50 ms of a deadline. An entry is never a miss early, and is found late only if the timer runs more than 40 ms late.
    • On an Apple M3 Max with tinylfu, a Get that hits took 11–15% longer and a Set 17 ns longer.
  • stats and expire stay separate. stats.Cache has no SetWithTTL; the package doc says so.
  • README. An Expiry section, and "What it does not do" as one bullet per limit.

Checked: golangci-lint run ./... finds nothing, and go test ./... passes on darwin/arm64 and under Rosetta for the inline checks. linux/386 vets and compiles; this PR's CI is its first run.

🤖 Generated with Claude Code

floatdrop and others added 2 commits November 23, 2026 15:52
expire.Wrap(cache, ttl) puts a clock in front of any evict.Cache that
holds expire.Entry values, and SetWithTTL gives one entry a time of its
own. An expired entry is a miss for Get, Peek, GetMany, Delete and All,
but stays until it is evicted, set again, deleted or cleared; Set hands
it back like any entry.

Readers look at a copy of the time that one shared timer updates every
10 ms, and at the time itself only within 50 ms of a deadline, so an
entry is never a miss early and is found late only if the timer runs
more than 40 ms late. On an Apple M3 Max with tinylfu, a Get that hits
took 15% longer on one CPU and 11-13% on eight, and a Set 17 ns longer.

The read path stays free of calls through a generic wrapper: expired is
at inline cost 79, and inlinecheck has probes for it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sizes in bytes, a loader, cleanup of expired entries and overwrites
that scale, each pointing to otter. The note that a wrapper could count
bytes from what Set and Delete hand back is gone: through expire, Delete
hands back nothing for an expired entry, so the count would drift.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@floatdrop
floatdrop merged commit b8a9c24 into main Nov 23, 2026
7 checks passed
@floatdrop
floatdrop deleted the expire branch November 23, 2026 11:38
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