go-mru – git.wntrmute.dev/kyle/go-mru Index | Files

package mru

import "git.wntrmute.dev/kyle/go-mru"

Index

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.

Source Files

mru.go timestamps.go

Version
v1.1.0 (latest)
Published
Aug 28, 2023
Platform
linux/amd64
Imports
5 packages
Last checked
2 months ago

Tools for package owners.