Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Impl ¶
type Impl[K comparable, V any] struct { // contains filtered or unexported fields }
Impl is a lazy key->value map. It's a wrapper around a map and a mutex. If values exceed their time-to-live, they are pruned at Get time.
func New ¶
func New[K comparable, V any]() *Impl[K, V]
New creates a new DecayMap of key type K and value type V.
Key types must be comparable to work with maps.
func (*Impl[K, V]) Cleanup ¶ added in v1.16.0
func (m *Impl[K, V]) Cleanup()
Cleanup removes all expired entries from the DecayMap.
func (*Impl[K, V]) Close ¶ added in v1.23.0
func (m *Impl[K, V]) Close()
Close stops the background cleanup worker. It's optional to call; maps live for the process lifetime in many cases. Call in tests or when you know you no longer need the map to avoid goroutine leaks.
func (*Impl[K, V]) Delete ¶ added in v1.21.0
Delete a value from the DecayMap by key.
If the value does not exist, return false. Return true after deletion.
func (*Impl[K, V]) Get ¶
Get gets a value from the DecayMap by key.
If a value has expired, forcibly delete it if it was not updated.