localcache

package
v0.0.0-...-71969ea Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CacheExist   = errors.New("local_cache: cache exist")
	CacheNoExist = errors.New("local_cache: cache no exist")
	CacheExpire  = errors.New("local_cache: cache expire")
	CacheTypeErr = errors.New("local_cache: cache incr type err")
	CacheGobErr  = errors.New("local_cache: cache save gob err")
)

Functions

func CacheErrExist

func CacheErrExist(e error) bool

func CacheErrExpire

func CacheErrExpire(e error) bool

func CacheErrNoExist

func CacheErrNoExist(e error) bool

func CacheErrTypeErr

func CacheErrTypeErr(e error) bool

func SetCapture

func SetCapture(capture func(key string, value interface{})) options.Option

SetCapture 设置缓存删除捕获函数的配置选项

func SetMember

func SetMember(m map[string]Iterator) options.Option

SetMember 设置初始化存储的成员对象

Types

type Cache

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

Cache 缓存包装结构体,通过嵌入cache提供缓存功能

func NewCache

func NewCache(options ...options.Option) Cache

NewCache 创建一个新的缓存实例

func (Cache) Add

func (c Cache) Add(k string, x interface{}, d time.Duration) error

Add 添加cache 如果存在则抛出异常

func (Cache) ChangeCapture

func (c Cache) ChangeCapture(f func(string, interface{}))

ChangeCapture 替换cache中capture的处理函数

func (Cache) Count

func (c Cache) Count() int

Count 计算现在 member 中 kv的数量 (所有)

func (Cache) Decrement

func (c Cache) Decrement(k string, n int64) error

Decrement 为k对应的value减少n n必须为数字类型

func (Cache) DecrementFloat

func (c Cache) DecrementFloat(k string, n float64) error

DecrementFloat 为k对应的value减少n n必须为浮点数类型

func (Cache) DecrementFloat32

func (c Cache) DecrementFloat32(k string, n float32) (float32, error)

DecrementFloat32 为k对应的value减少n n必须为float32类型

func (Cache) DecrementFloat64

func (c Cache) DecrementFloat64(k string, n float64) (float64, error)

DecrementFloat64 为k对应的value减少n n必须为float64类型

func (Cache) DecrementInt

func (c Cache) DecrementInt(k string, n int) (int, error)

DecrementInt 为k对应的value减少n n必须为int类型

func (Cache) DecrementInt16

func (c Cache) DecrementInt16(k string, n int16) (int16, error)

DecrementInt16 为k对应的value减少n n必须为int16类型

func (Cache) DecrementInt32

func (c Cache) DecrementInt32(k string, n int32) (int32, error)

DecrementInt32 为k对应的value减少n n必须为int32类型

func (Cache) DecrementInt64

func (c Cache) DecrementInt64(k string, n int64) (int64, error)

DecrementInt64 为k对应的value减少n n必须为int64类型

func (Cache) DecrementInt8

func (c Cache) DecrementInt8(k string, n int8) (int8, error)

DecrementInt8 为k对应的value减少n n必须为int8类型

func (Cache) DecrementUint

func (c Cache) DecrementUint(k string, n uint) (uint, error)

DecrementUint 为k对应的value减少n n必须为uint类型

func (Cache) DecrementUint16

func (c Cache) DecrementUint16(k string, n uint16) (uint16, error)

DecrementUint16 为k对应的value减少n n必须为uint16类型

func (Cache) DecrementUint32

func (c Cache) DecrementUint32(k string, n uint32) (uint32, error)

DecrementUint32 为k对应的value减少n n必须为uint32类型

func (Cache) DecrementUint64

func (c Cache) DecrementUint64(k string, n uint64) (uint64, error)

DecrementUint64 为k对应的value减少n n必须为uint64类型

func (Cache) DecrementUint8

func (c Cache) DecrementUint8(k string, n uint8) (uint8, error)

DecrementUint8 为k对应的value减少n n必须为uint8类型

func (Cache) DecrementUintPtr

func (c Cache) DecrementUintPtr(k string, n uintptr) (uintptr, error)

DecrementUintPtr 为k对应的value减少n n必须为uintptr类型

func (Cache) Delete

func (c Cache) Delete(k string)

Delete 删除k的cache 如果 capture != nil 会调用 capture 函数 将 kv传入

func (Cache) DeleteExpire

func (c Cache) DeleteExpire()

DeleteExpire 删除已经过期的kv

func (Cache) Flush

func (c Cache) Flush()

Flush 释放member成员

func (Cache) Get

func (c Cache) Get(k string) (interface{}, bool)

Get 根据key获取 cache

func (Cache) GetWithExpire

func (c Cache) GetWithExpire(k string) (interface{}, time.Time, bool)

GetWithExpire 根据key获取 cache 并带出过期时间

func (Cache) Increment

func (c Cache) Increment(k string, n int64) error

Increment 为k对应的value增加n n必须为数字类型

func (Cache) IncrementFloat

func (c Cache) IncrementFloat(k string, n float64) error

IncrementFloat 为k对应的value增加n n必须为浮点数类型

func (Cache) IncrementFloat32

func (c Cache) IncrementFloat32(k string, n float32) (float32, error)

IncrementFloat32 为k对应的value增加n n必须为float32类型

func (Cache) IncrementFloat64

func (c Cache) IncrementFloat64(k string, n float64) (float64, error)

IncrementFloat64 为k对应的value增加n n必须为float64类型

func (Cache) IncrementInt

func (c Cache) IncrementInt(k string, n int) (int, error)

IncrementInt 为k对应的value增加n n必须为int类型

func (Cache) IncrementInt16

func (c Cache) IncrementInt16(k string, n int16) (int16, error)

IncrementInt16 为k对应的value增加n n必须为int16类型

func (Cache) IncrementInt32

func (c Cache) IncrementInt32(k string, n int32) (int32, error)

IncrementInt32 为k对应的value增加n n必须为int32类型

func (Cache) IncrementInt64

func (c Cache) IncrementInt64(k string, n int64) (int64, error)

IncrementInt64 为k对应的value增加n n必须为int64类型

func (Cache) IncrementInt8

func (c Cache) IncrementInt8(k string, n int8) (int8, error)

IncrementInt8 为k对应的value增加n n必须为int8类型

func (Cache) IncrementUint

func (c Cache) IncrementUint(k string, n uint) (uint, error)

IncrementUint 为k对应的value增加n n必须为uint类型

func (Cache) IncrementUint16

func (c Cache) IncrementUint16(k string, n uint16) (uint16, error)

IncrementUint16 为k对应的value增加n n必须为uint16类型

func (Cache) IncrementUint32

func (c Cache) IncrementUint32(k string, n uint32) (uint32, error)

IncrementUint32 为k对应的value增加n n必须为uint32类型

func (Cache) IncrementUint64

func (c Cache) IncrementUint64(k string, n uint64) (uint64, error)

IncrementUint64 为k对应的value增加n n必须为uint64类型

func (Cache) IncrementUint8

func (c Cache) IncrementUint8(k string, n uint8) (uint8, error)

IncrementUint8 为k对应的value增加n n必须为uint8类型

func (Cache) IncrementUintPtr

func (c Cache) IncrementUintPtr(k string, n uintptr) (uintptr, error)

IncrementUintPtr 为k对应的value增加n n必须为uintptr类型

func (Cache) Iterator

func (c Cache) Iterator() map[string]Iterator

Iterator 返回 cache 中所有有效的对象

func (Cache) Load

func (c Cache) Load(r io.Reader) error

Load 从r 中加载 c.member

func (Cache) LoadFile

func (c Cache) LoadFile(path string) error

LoadFile 从 path 中加载 c.member

func (Cache) Replace

func (c Cache) Replace(k string, x interface{}, d time.Duration) error

Replace 替换cache 如果有就设置没有就抛出异常

func (Cache) Save

func (c Cache) Save(w io.Writer) (err error)

Save 将 c.member 写入到 w 中

func (Cache) SaveFile

func (c Cache) SaveFile(path string) error

SaveFile 将 c.member 保存到 path 中

func (Cache) Set

func (c Cache) Set(k string, v interface{}, d time.Duration)

Set 设置缓存项,无论是否存在都会覆盖

func (Cache) SetDefault

func (c Cache) SetDefault(k string, v interface{})

SetDefault 添加cache 无论是否存在都会覆盖 超时设置为创建cache的默认时间

func (Cache) SetNoExpire

func (c Cache) SetNoExpire(k string, v interface{})

SetNoExpire 添加cache 无论是否存在都会覆盖 超时设置为0(永不过期)

func (Cache) Shutdown

func (c Cache) Shutdown() error

Shutdown 关闭缓存,释放资源

type Config

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

Config 本地缓存配置结构体

func NewConfig

func NewConfig(opts ...options.Option) *Config

NewConfig 创建一个新的本地缓存配置实例

type Iterator

type Iterator struct {
	Val    interface{} // 实际存储的对象
	Expire int64       // 过期时间,如果设置0,则表示不过期
}

func (*Iterator) Expired

func (i *Iterator) Expired(e ...int64) bool

Expired 判断缓存是否过期

Jump to

Keyboard shortcuts

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