Documentation
¶
Index ¶
- type Cache
- func (a Cache[K, V]) All() iter.Seq2[K, Handle[V]]
- func (a Cache[K, V]) Capacity() int64
- func (a Cache[K, V]) Clear()
- func (a Cache[K, V]) Evict() (noSpace bool)
- func (a Cache[K, V]) Get(k K) (Handle[V], bool)
- func (a Cache[K, V]) Handles() int
- func (a Cache[K, V]) Len() int
- func (a Cache[K, V]) Peek(k K) (Handle[V], bool)
- func (a Cache[K, V]) Promote(k K)
- func (a Cache[K, V]) Set(k K, v V) Handle[V]
- func (a Cache[K, V]) SetAvailableCapacity(available, max int64)
- func (a Cache[K, V]) SetCapacity(new int64) (old int64)
- func (a Cache[K, V]) SetS(k K, v V, size uint32) Handle[V]
- func (a Cache[K, V]) Size() int64
- func (a Cache[K, V]) SwapCapacity(old, new int64) (swapped bool)
- type CacheOptions
- type Handle
- type Node
- type Releaser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V Releaser] struct { // contains filtered or unexported fields }
Similar to cache.Cache except values are Released when evicted, but only after all the Handles of that value are released. This is useful when the value needs to track a reusable item to know all callers are done with the value. Concurrent safe.
func NewCache ¶
func NewCache[K comparable, V Releaser](o CacheOptions[K, V]) Cache[K, V]
func (Cache[K, V]) All ¶
Results ordered by most->least. Will block. Caller must release each Handle.
func (Cache[K, V]) Clear ¶
func (a Cache[K, V]) Clear()
Evicts all and resets. Does not change capacity. Will block.
func (Cache[K, V]) SetAvailableCapacity ¶
available (+/-) should not consider taken space in cache.
func (Cache[K, V]) SetCapacity ¶
func (Cache[K, V]) SetS ¶
Replaces existing values, which are evicted. A min size of 1 will be used. Caller must release Handle.
func (Cache[K, V]) SwapCapacity ¶
type CacheOptions ¶
type CacheOptions[K any, V Releaser] struct { Expiration time.Duration // Defaults to forever. Capacity int64 // Defaults to 100. MapCreator func() maps.Map[K, *cache.CacheValue[*Node[V]]] // defaults to maps.Sync PolicyCreator func() policy.Policy[K] // defaults to policy.NewARC Evict func(_ K, _ V, Release func()) // Caller must Release, not V.Release. EvictSkip bool }
type Node ¶
type Node[T Releaser] struct { // contains filtered or unexported fields }
A node that tracks Releases from its Handles and only releases the underlying value once all Handles and the node itself have been released. Concurrent safe.