Documentation ¶
Index ¶
Constants ¶
const (
// DefaultCacity is the default cache capacity
DefaultCapacity = 10000
)
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 lru cache. It automatically removes elements as new elements are added if the capacity is reached. Items are removes based on how recently they were used where the oldest items are removed first.
func New ¶
func New[K comparable, V any](cacheOptions ...CacheOption) *Cache[K, V]
New initializes a new lru cache with the given capacity.
func (*Cache[K, V]) Get ¶
Get an item from the cache. This operation updates recent usage of the item.
type CacheOption ¶
type CacheOption interface {
// contains filtered or unexported methods
}
CacheOption configurs a lru cache.
func WithCapacity ¶
func WithCapacity(capacity int) CacheOption
WithCapacity configures how many items can be stored before old items begin to be deleted.
type SyncCache ¶
type SyncCache[K comparable, V any] struct { // contains filtered or unexported fields }
SyncCache is a threadsafe lru cache.
func NewSync ¶
func NewSync[K comparable, V any](options ...CacheOption) *SyncCache[K, V]
New initializes a new lru cache with the given capacity.
func (*SyncCache[K, V]) Flush ¶
func (c *SyncCache[K, V]) Flush()
Flush deletes all items from the cache.
func (*SyncCache[K, V]) Get ¶
Get an item from the cache. This operation updates recent usage of the item.