lru

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

LRU Cache

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache lru cache

func New

func New(size int) (*Cache, error)

New create a new LRU cache

func (*Cache) Clear

func (cache *Cache) Clear()

Clear is used to clear the cache

func (*Cache) Del

func (cache *Cache) Del(key string) error

Del remove is used to purge a key from the cache

func (*Cache) DelMulti

func (cache *Cache) DelMulti(keys []string)

DelMulti mulit remove values

func (*Cache) Get

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

Get looks up a key's value from the cache.

func (*Cache) GetDel

func (cache *Cache) GetDel(key string) (value interface{}, ok bool)

GetDel looks up a key's value from the cache, then remove it.

func (*Cache) GetMulti

func (cache *Cache) GetMulti(keys []string) map[string]interface{}

GetMulti mulit get values

func (*Cache) GetSet

func (cache *Cache) GetSet(key string, ttl time.Duration, getValue func(key string) (interface{}, error)) (interface{}, error)

GetSet looks up a key's value from the cache. if does not exist add to the cache

func (*Cache) GetSetMulti

func (cache *Cache) GetSetMulti(keys []string, ttl time.Duration, getValue func(key string) (interface{}, error)) map[string]interface{}

GetSetMulti mulit get values, if does not exist add to the cache

func (*Cache) Has

func (cache *Cache) Has(key string) bool

Has check if the cache is exist ( without updating recency or frequency )

func (*Cache) Keys

func (cache *Cache) Keys() []string

Keys returns all the cached keys

func (*Cache) Len

func (cache *Cache) Len() int

Len returns the number of cached entries

func (*Cache) Set

func (cache *Cache) Set(key string, value interface{}, ttl time.Duration) error

Set adds a value to the cache.

func (*Cache) SetMulti

func (cache *Cache) SetMulti(values map[string]interface{}, ttl time.Duration)

SetMulti mulit set values

Jump to

Keyboard shortcuts

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