memorycache

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 3 Imported by: 0

README

memorycache

simple memory cache for Golang, with LRU/LFU eviction policies.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache added in v1.1.0

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

func New added in v1.0.6

func New(co *Option) *Cache

func (*Cache) Get added in v1.1.0

func (cache *Cache) Get(key string) (val any, ok bool)

func (*Cache) GetBytes added in v1.1.0

func (cache *Cache) GetBytes(key string) []byte

func (*Cache) GetFloat added in v1.1.0

func (cache *Cache) GetFloat(key string) float64

func (*Cache) GetInt added in v1.1.0

func (cache *Cache) GetInt(key string) int

func (*Cache) GetString added in v1.1.0

func (cache *Cache) GetString(key string) string

func (*Cache) Set added in v1.1.0

func (cache *Cache) Set(key string, val any, expire ...time.Duration)

expire为可选的过期时间,当expire>0时,即便缓存没有满,数据也会因超时被清理

type EvictionPolicy added in v1.0.6

type EvictionPolicy byte
const (
	PolicyLRU EvictionPolicy = iota
	PolicyLFU
)

type Option added in v1.1.0

type Option struct {
	Capacity int            //最大缓存数, 默认1024条
	Policy   EvictionPolicy //缓存清理策略,默认LRU
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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