lrucache

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package lrucache provides a very basic LRU cache implementation.

The lru package provides a very basic LRU cache implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Add a new value to the cache and updates the recent-ness. Returns true if an eviction occurred.
	Add(key, value interface{}) bool

	// Return a key's value if found in the cache and updates the recent-ness.
	Get(key interface{}) (value interface{}, ok bool)

	// Check if a key exists without updating the recent-ness.
	Contains(key interface{}) (ok bool)

	// Remove a key from the cache.
	Remove(key interface{}) bool

	// Return a slice which all keys ordered by newest to oldest.
	Keys() []interface{}

	// Return number of entry in the cache.
	Length() int

	// Remove all entries form the cache.
	Purge()
}

Cache defines the interface for the LRU cache

type LRUCache

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

LRU struct to represent the LRU cache

func NewLRUCache

func NewLRUCache(size int) (*LRUCache, error)

New constructs a new cache instance

func (*LRUCache) Add

func (c *LRUCache) Add(key, value interface{}) (evicted bool)

func (*LRUCache) Contains

func (c *LRUCache) Contains(key interface{}) (ok bool)

func (*LRUCache) Get

func (c *LRUCache) Get(key interface{}) (value interface{}, ok bool)

func (*LRUCache) Keys

func (c *LRUCache) Keys() []interface{}

func (*LRUCache) Length

func (c *LRUCache) Length() int

func (*LRUCache) Purge

func (c *LRUCache) Purge()

func (*LRUCache) Remove

func (c *LRUCache) Remove(key interface{}) (present bool)

Jump to

Keyboard shortcuts

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