Documentation
¶
Index ¶
- type Cache
- func (c *Cache[K, V]) Capacity() int
- func (c *Cache[K, V]) Clear()
- func (c *Cache[K, V]) Close()
- func (c *Cache[K, V]) Delete(key K)
- func (c *Cache[K, V]) Get(key K) (V, bool)
- func (c *Cache[K, V]) Has(key K) bool
- func (c *Cache[K, V]) Range(f func(key K, value V) bool)
- func (c *Cache[K, V]) Set(key K, value V) bool
- func (c *Cache[K, V]) SetIfAbsent(key K, value V) bool
- func (c *Cache[K, V]) SetIfAbsentWithTTL(key K, value V, ttl time.Duration) bool
- func (c *Cache[K, V]) SetWithTTL(key K, value V, ttl time.Duration) bool
- func (c *Cache[K, V]) Size() int
- func (c *Cache[K, V]) Stats() *stats.Stats
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache is a structure performs a best-effort bounding of a hash table using eviction algorithm to determine which entries to evict when the capacity is exceeded.
func NewCache ¶
func NewCache[K comparable, V any](c Config[K, V]) *Cache[K, V]
NewCache returns a new cache instance based on the settings from Config.
func (*Cache[K, V]) Clear ¶
func (c *Cache[K, V]) Clear()
Clear clears the hash table, all policies, buffers, etc.
NOTE: this operation must be performed when no requests are made to the cache otherwise the behavior is undefined.
func (*Cache[K, V]) Close ¶
func (c *Cache[K, V]) Close()
Close clears the hash table, all policies, buffers, etc and stop all goroutines.
NOTE: this operation must be performed when no requests are made to the cache otherwise the behavior is undefined.
func (*Cache[K, V]) Delete ¶
func (c *Cache[K, V]) Delete(key K)
Delete removes the association for this key from the cache.
func (*Cache[K, V]) Range ¶
Range iterates over all items in the cache.
Iteration stops early when the given function returns false.
func (*Cache[K, V]) Set ¶
Set associates the value with the key in this cache.
If it returns false, then the key-value item had too much cost and the Set was dropped.
func (*Cache[K, V]) SetIfAbsent ¶
SetIfAbsent if the specified key is not already associated with a value associates it with the given value.
If the specified key is not already associated with a value, then it returns false.
Also, it returns false if the key-value item had too much cost and the SetIfAbsent was dropped.
func (*Cache[K, V]) SetIfAbsentWithTTL ¶
SetIfAbsentWithTTL if the specified key is not already associated with a value associates it with the given value and sets the custom ttl for this key-value item.
If the specified key is not already associated with a value, then it returns false.
Also, it returns false if the key-value item had too much cost and the SetIfAbsent was dropped.
func (*Cache[K, V]) SetWithTTL ¶
SetWithTTL associates the value with the key in this cache and sets the custom ttl for this key-value item.
If it returns false, then the key-value item had too much cost and the SetWithTTL was dropped.