mru

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

README

MRU

A Most Recently Used cache implementation in Go. It tries to mimic the behaviour of a hash map.

For example usages, see mru_test.go.

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
}

A Cache is a map that retains a limited number of items. It must be initialized with New, providing a maximum capacity for the cache. Only the most recently used items are retained.

func New

func New(cap int) *Cache

New must be used to create a new Cache.

func (*Cache) ConsistencyCheck

func (c *Cache) ConsistencyCheck() error

ConsistencyCheck runs a series of checks to ensure that the cache's data structures are consistent. It is not normally required, and it is primarily used in testing.

func (*Cache) Get

func (c *Cache) Get(k string) (interface{}, bool)

Get returns the value stored in the cache. If the item isn't present, it will return false.

func (*Cache) Has

func (c *Cache) Has(k string) bool

Has returns true if the cache has an entry for k. It will not update the timestamp on the item.

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of items currently in the cache.

func (*Cache) Store

func (c *Cache) Store(k string, v interface{})

Store adds the value v to the cache under the k.

Jump to

Keyboard shortcuts

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