lru

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2022 License: Apache-2.0 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 {
	*sync.RWMutex
	// contains filtered or unexported fields
}

Cache is a cache with the least-recently-used policy.

func NewCache

func NewCache(cap int) *Cache

NewCache creates a new Cache instance with the given cap. If cap == 0, nil is returned.

func (Cache) Back

func (c Cache) Back() []byte

Back returns a copy of value at the back of the cache

func (*Cache) Cap

func (c *Cache) Cap() int

Cap returns the max amount of items that can be stored in the cache.

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all items from the cache.

func (Cache) Front

func (c Cache) Front() []byte

Front returns a copy of the value at front of the cache

func (*Cache) Get

func (c *Cache) Get(k []byte) []byte

Get returns the value for the given key. If the key is not found then returns nil.

func (*Cache) Len

func (c *Cache) Len() int

Len returns the current amount of items in the cache.

func (*Cache) Put

func (c *Cache) Put(k []byte, v []byte)

Put adds a new key-value pair to the cache. If the cache is full then the least-recently-used key-value pair is removed. If the key already exist in the cache then the node will be replaced and put at the front of the cache.

Jump to

Keyboard shortcuts

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