Documentation
¶
Overview ¶
Package weakcache provides a concurrency-safe cache keyed by pointer identity that does not keep its keys alive.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K, V any] struct { // contains filtered or unexported fields }
Cache maps pointers to values without retaining the pointers. Entries are found by address and verified through a weak pointer, so a hit costs a map lookup, an entry is dropped once the garbage collector reclaims its key, and an object later allocated at a reused address never sees the entry of the object that lived there before.
The zero value is ready to use. Keys must not be nil.
func (*Cache[K, V]) Clear ¶
func (c *Cache[K, V]) Clear()
Clear invalidates every entry. Invalidated entries for live keys are updated in place by their next Store and entries for unreachable keys are removed as the keys are reclaimed, so clearing never registers a second cleanup for a key that is still alive.
func (*Cache[K, V]) Len ¶
Len reports the number of entries currently held, including invalidated entries that have not been replaced or reclaimed yet.