Documentation
¶
Overview ¶
Package expiry orders keys by expiry time, so a bounded cache can find what to drop without scanning its whole map.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Index ¶
type Index[K comparable] struct { // contains filtered or unexported fields }
Index is a min-heap of keys ordered by expiry. It holds no values and takes no lock: the cache owns both, and tracks a key when it first inserts it.
Extending a key's TTL is deliberately not reported to the index. A cache that refreshes on every read would otherwise pay a heap fix on its hottest path, so the index is allowed to hold an expiry earlier than the truth. That is why Expired and Soonest hand back the expiry they recorded: the caller compares it with its own map, and re-Tracks a key that has moved. A key the cache has already deleted is simply discarded when it surfaces.
func (*Index[K]) Expired ¶
Expired pops the next key due at now, with the expiry the index holds for it. It reports false when the soonest key is not due yet.
func (*Index[K]) Len ¶
Len is how many keys are tracked, including ones the cache has deleted and the index has not surfaced yet.
func (*Index[K]) Soonest ¶
Soonest pops the key closest to expiry, with the expiry the index holds for it. It reports false when the index is empty.