eaglecache

package
v0.2.0 Latest Latest
Warning

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

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

README

go-cache

codebeat badge

供Go语言使用的缓存结构

特性:

  • 以interface{}实现,支持任意数据结构
  • 根据自定义TTL(生存时间)自动化地销毁过期缓存元素
  • 高效复用请求

高效复用请求

当新元素被添加,会被自动置为阻塞态,所有对其调用都会被阻塞,直到Update函数被第一次调用为止。适用于只需单次处理,多次使用的场景。例如DNS缓存。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache 缓存 必须使用CreateCache函数进行初始化 该结构体线程安全

func CreateCache

func CreateCache(defaultTTL ...time.Duration) *Cache

CreateCache 创建Cache

func (*Cache) Close

func (cache *Cache) Close()

Close 关闭Cache,退出可能存在的TTL检查服务

func (*Cache) Get

func (cache *Cache) Get(key interface{}) (node *CacheNode, loaded bool)

Get 拿到key对应的节点 并且返回节点是否之前存在

type CacheNode

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

CacheNode 缓存节点 CacheNode 必须通过函数createcacheNode进行创建 本结构体线程安全

func (*CacheNode) Destroy

func (cache *CacheNode) Destroy()

Destroy 销毁Cache

func (*CacheNode) Update

func (cache *CacheNode) Update(value interface{})

Update 更新Cache的Value 更新操作会解除节点的阻塞

func (*CacheNode) Wait4Value

func (cache *CacheNode) Wait4Value() (value interface{}, err error)

Wait4Value 检查Cache,阻塞于waiting状态,并于状态改变后返回value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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