lrucache

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2020 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Set(key string, value interface{})  // 设置缓存
	Get(key string) (interface{}, bool) // 获取缓存
	Delete(key string)                  // 删除缓存
	Status() *Status                    // 当前状态
	GC()                                // 垃圾回收
}

this is a interface which defines some common functions

type LRUCache

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

LRU缓存

func New

func New(maxSize int, ttl time.Duration) *LRUCache

如果 maxSize = 0 则表示不限制

func (*LRUCache) Delete

func (c *LRUCache) Delete(key string)

删除缓存

func (*LRUCache) GC

func (c *LRUCache) GC()

缓存垃圾回收

func (*LRUCache) Get

func (c *LRUCache) Get(key string) (interface{}, bool)

查询缓存

func (*LRUCache) Set

func (c *LRUCache) Set(key string, value interface{})

设置缓存

func (*LRUCache) SetEx

func (c *LRUCache) SetEx(key string, value interface{}, ttl time.Duration)

设置缓存,指定过期时间

func (*LRUCache) StartAutoGC

func (c *LRUCache) StartAutoGC(interval time.Duration)

自动刷新

func (*LRUCache) Status

func (c *LRUCache) Status() *Status

缓存状态

func (*LRUCache) StopAutoGC

func (c *LRUCache) StopAutoGC()

停止自动刷新

type Status

type Status struct {
	Gets    uint64 `json:"gets"` // 查询次数
	Hits    uint64 `json:"hits"` // 命中次数
	MaxSize int    `json:"max"`  // 历史最大缓存数量
	Size    int    `json:"size"` // 当前缓存数量
}

return status of Cache

Jump to

Keyboard shortcuts

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