slru

package module
v0.0.0-...-5d0b366 Latest Latest
Warning

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

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

README

slru

thread safe LRU implement of Golang. modified by https://github.com/golang/groupcache/blob/master/lru/lru.go

Documentation

Overview

Package lru implements an 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 evicted. Zero means no limit.
	MaxEntries int

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

Cache is an LRU cache. It is not safe for concurrent access.

func New

func New(maxEntries int) *Cache

New creates a new Cache. If maxEntries is zero, the cache has no limit and it's assumed that eviction is done by the caller.

func (*Cache) Add

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

Add adds a value to the cache.

func (*Cache) Clear

func (c *Cache) Clear()

Clear purges all stored items from the cache.

func (*Cache) Get

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

Get looks up a key's value 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 Key)

Remove removes the provided key from the cache.

func (*Cache) RemoveOldest

func (c *Cache) RemoveOldest()

RemoveOldest removes the oldest item from the cache.

type Key

type Key interface{}

A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators

type List

type List struct {
	sync.Mutex
	// contains filtered or unexported fields
}

List is thread safe list base on list.List

func NewList

func NewList() *List

func (*List) Back

func (l *List) Back() *list.Element

func (*List) Front

func (l *List) Front() *list.Element

func (*List) Init

func (l *List) Init() *List

func (*List) InsertAfter

func (l *List) InsertAfter(v interface{}, mark *list.Element) *list.Element

func (*List) InsertBefore

func (l *List) InsertBefore(v interface{}, mark *list.Element) *list.Element

func (*List) Len

func (l *List) Len() int

func (*List) MoveAfter

func (l *List) MoveAfter(e, mark *list.Element)

func (*List) MoveBefore

func (l *List) MoveBefore(e, mark *list.Element)

func (*List) MoveToBack

func (l *List) MoveToBack(e *list.Element)

func (*List) MoveToFront

func (l *List) MoveToFront(e *list.Element)

func (*List) PushBack

func (l *List) PushBack(v interface{}) *list.Element

func (*List) PushBackList

func (l *List) PushBackList(other *List)

func (*List) PushFront

func (l *List) PushFront(v interface{}) *list.Element

func (*List) PushFrontList

func (l *List) PushFrontList(other *List)

func (*List) Remove

func (l *List) Remove(e *list.Element) interface{}

Jump to

Keyboard shortcuts

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