gocache

package module
v0.0.2 Latest Latest
Warning

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

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

README

gocache

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 一个内存缓存库,支持过期和后台更新

func NewCache added in v0.0.2

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

NewCache 初始化缓存,缓存数量超过size将使用lru算法淘汰

func (*Cache) Clean added in v0.0.2

func (c *Cache) Clean()

Clean 清理所有缓存内容

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete 删除指定键缓存

func (*Cache) Get

func (c *Cache) Get(key string, loader func() (interface{}, error), expire time.Duration, backgroupUpdate bool) (interface{}, error)

Get 获取key缓存的值,如不存在则使用loader函数加载缓存

如果使用后台更新,函数直接返回过期的值,并使用协程调用loader更新缓存

Jump to

Keyboard shortcuts

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