lru

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package lru implements a LRU cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// MaxEntries is the maximum number of cache entries
	// before an item is purged. Zero means no limit.
	MaxEntries int

	// OnPurged specifies a function to be executed
	// when an entry is purged from the cache.
	OnPurged func(key interface{}, value interface{})
	// contains filtered or unexported fields
}

Cache is a LRU cache.

func New

func New(maxEntries int) *Cache

New creates a new cache, if maxEntries is zero, the cache has no limit.

func (*Cache) Add

func (c *Cache) Add(key interface{}, value interface{})

Add adds value to the cache.

func (*Cache) Clear

func (c *Cache) Clear()

Clear purges all items from the cache.

func (*Cache) Get

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

Get looks up value by key from the cache.

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of items in the cache.

func (*Cache) Remove

func (c *Cache) Remove(key interface{})

Remove removes the provided key from the cache.

func (*Cache) RemoveOldest

func (c *Cache) RemoveOldest()

RemoveOldest removes the oldest item from the cache.

Jump to

Keyboard shortcuts

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