cache

package
v0.0.0-...-3077202 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dict

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

Dict 字典

func New

func New(opts ...DictOption) *Dict

New 创建一个字典

func (*Dict) All

func (d *Dict) All() (all map[string]interface{})

All 获取所有key-value

func (*Dict) CheckAll

func (d *Dict) CheckAll()

CheckAll 检测所有key的过期

func (*Dict) Del

func (d *Dict) Del(k string) (ok bool)

Del 删除key

func (*Dict) DelExpired

func (d *Dict) DelExpired(k string) (ok bool)

DelExpired 删除key对应的过期数据

func (*Dict) ExpireAt

func (d *Dict) ExpireAt(k string, t time.Time) (has bool)

ExpireAt 设置key的过期时间

func (*Dict) ExpireDur

func (d *Dict) ExpireDur(k string, dur time.Duration) (has bool)

ExpireDur 设置key的过期时长

func (*Dict) Get

func (d *Dict) Get(k string) (val interface{}, has bool)

Get 获取key对应的value

func (*Dict) GetDel

func (d *Dict) GetDel(k string) (val interface{}, has bool)

GetDel 获取key对应的value并删除

func (*Dict) GetSet

func (d *Dict) GetSet(k string, v interface{}, opts ...ItemOption) (val interface{}, has bool)

GetSet 获取key对应的value并设置新值

func (*Dict) GetSetX

func (d *Dict) GetSetX(k string, v interface{}, opts ...ItemOption) (val interface{}, has bool)

GetSetX 获取key对应的value并设置新值,如果key不存在则设置新值

func (*Dict) Handle

func (d *Dict) Handle(k string, h ExpiredHandler) (has bool)

Handle 设置key的过期处理器

func (*Dict) Has

func (d *Dict) Has(k string) (has bool)

Has 判断key是否存在

func (*Dict) Len

func (d *Dict) Len() (cnt int)

Len 获取key的数量

func (*Dict) Set

func (d *Dict) Set(k string, v interface{}, opts ...ItemOption) (ok bool)

Set 设置key-value

func (*Dict) SetX

func (d *Dict) SetX(k string, v interface{}, opts ...ItemOption) (has bool)

SetX 设置key-value,如果key不存在则设置新值

func (*Dict) TTL

func (d *Dict) TTL(k string) (dur time.Duration)

TTL 获取key的剩余时间

type DictOption

type DictOption func(*Dict)

DictOption 词典选项

func DictCheckInterval

func DictCheckInterval(dur time.Duration) DictOption

DictCheckInterval 设置检查间隔

func DictExpireHandler

func DictExpireHandler(h ExpiredHandler) DictOption

DictExpireHandler 设置过期处理器

func DictShardNum

func DictShardNum(n int) DictOption

DictShardNum 设置分片数量

type ExpiredHandler

type ExpiredHandler func(k string, v interface{})

type ItemOption

type ItemOption func(*item)

ItemOption 元素选项

func ItemExAt

func ItemExAt(t time.Time) ItemOption

ItemExAt 设置过期时间

func ItemExDur

func ItemExDur(d time.Duration) ItemOption

ItemExDur 设置过期时长

func ItemExHand

func ItemExHand(h ExpiredHandler) ItemOption

ItemExHand 设置过期处理器

Jump to

Keyboard shortcuts

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