lru

package
v3.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2023 License: ISC Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache implements a least-recently-updated (LRU) cache with nearly O(1) lookups and inserts. Items are added to the cache up to a limit, at which point further additions will evict the least recently added item. The zero value is not valid and Caches must be created with NewCache. All Cache methods are concurrent safe.

func NewCache

func NewCache(limit int) Cache

NewCache creates an initialized and empty LRU cache.

func (*Cache) Add

func (c *Cache) Add(item interface{})

Add adds an item to the LRU cache, removing the oldest item if the new item is not already a member, or marking item as the most recently added item if it is already present.

func (*Cache) Contains

func (c *Cache) Contains(v interface{}) bool

Contains checks whether v is a member of the LRU cache.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL