Documentation ¶
Overview ¶
Package lru provides a generic, size-limited, LRU (Least Recently Used) cache with optional metrics collection and reporting. It wraps the golang-lru/v2 caching library, adding support for custom metrics tracking cache hits, misses, evictions, and other cache operations.
This package supports configuring key aspects of cache behavior, including maximum cache size, and custom metrics collection.
Index ¶
- type Cache
- func (lc *Cache[T]) Clear()
- func (lc *Cache[T]) Contents() string
- func (lc *Cache[T]) Count() int
- func (lc *Cache[T]) Delete(key string)
- func (lc *Cache[T]) Exists(key string) bool
- func (lc *Cache[T]) Get(key string) (T, bool)
- func (lc *Cache[T]) Keys() []string
- func (lc *Cache[T]) Set(key string, val T)
- func (lc *Cache[T]) Values() []T
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[T any] struct { // contains filtered or unexported fields }
Cache is a generic LRU-sized cache that stores key-value pairs with a maximum size limit. It wraps the lru.Cache library and adds support for custom metrics collection.
func NewCache ¶
NewCache creates a new Cache with optional configuration parameters. It takes a cache name and a variadic list of options.
type Option ¶
Option defines a functional option for configuring the Cache.
func WithCapacity ¶
WithCapacity is a functional option to set the maximum number of items the cache can hold. If the capacity is not set, the default value (128_000) is used.
func WithMetricsCollector ¶
func WithMetricsCollector[T any](collector cache.EvictionMetricsCollector) Option[T]
WithMetricsCollector is a functional option to set a custom metrics collector.