Documentation
¶
Index ¶
- func New[K comparable, V any](capacity int) *builder[K, V]
- type Cache
- func (cache *Cache[K, V]) Capacity() (capacity int)
- func (cache *Cache[K, V]) Clear()
- func (cache *Cache[K, V]) Get(key K) (result optionext.Option[V])
- func (cache *Cache[K, V]) Len() (length int)
- func (cache *Cache[K, V]) PercentageFull() (full float64)
- func (cache *Cache[K, V]) Remove(key K)
- func (cache *Cache[K, V]) Set(key K, value V)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New[K comparable, V any](capacity int) *builder[K, V]
New initializes a builder to create an LRU cache.
Types ¶
type Cache ¶ added in v0.2.0
type Cache[K comparable, V any] struct { // contains filtered or unexported fields }
Cache is a configured least recently used cache ready for use.
func (*Cache[K, V]) Capacity ¶ added in v0.2.0
Capacity returns the current configured capacity of the cache.
func (*Cache[K, V]) Clear ¶ added in v0.2.0
func (cache *Cache[K, V]) Clear()
Clear empties the cache.
func (*Cache[K, V]) Get ¶ added in v0.2.0
Get attempts to find an existing cache entry by key. It returns an Option you must check before using the underlying value.
func (*Cache[K, V]) Len ¶ added in v0.2.0
Len returns the current size of the cache. The result will include items that may be expired past the max age as they are passively expired.
func (*Cache[K, V]) PercentageFull ¶ added in v0.4.0
PercentageFull is a convenience function to grab the information with one lock instead of the two that would have been needed by calling `Len` and `Capacity` separately.
Click to show internal directories.
Click to hide internal directories.