Documentation ¶
Overview ¶
Package weakmap implements a weak reference map in Go.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // Coster is a function that returns the cost of a value, // policed by MaxCost. If left nil, Coster becomes a function // that always returns 1. Coster func(V) int // MaxCost is the maximum cost of the cache. // When a Set would cause the cost to exceed MaxCost, // the least recently used entries are evicted until // the cost is below MaxCost. MaxCost int // contains filtered or unexported fields }
Map implements a LRU weak map safe for concurrent use. The zero value is an empty map ready for use.
When the Go GC runs, the oldest entries proportional to memory pressure are evicted.
func (*Map[K, V]) Delete ¶
func (l *Map[K, V]) Delete(key K)
Delete removes an entry from the cache.
func (*Map[K, V]) Do ¶
Do is a helper that retrieves a value from the cache, if it exists, and calls the provided function to compute the value if it does not.
Directories ¶
Path | Synopsis |
---|---|
Package doublelist implements a doubly-linked list.
|
Package doublelist implements a doubly-linked list. |
example
|
|
Click to show internal directories.
Click to hide internal directories.