Skip to content

Latest commit

 

History

History
124 lines (67 loc) · 2.56 KB

lru.md

File metadata and controls

124 lines (67 loc) · 2.56 KB

lru

import "github.com/andy2046/gopie/pkg/lru"

Package lru implements a LRU cache.

lru.go

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(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 (c *Cache) RemoveOldest()

RemoveOldest removes the oldest item from the cache.


Generated by godoc2md