cache

package
v4.2.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxSize = 10000

DefaultMaxSize 默认最大缓存条目数

Variables

View Source
var ErrKeyNotFound = errors.New("key not found")

ErrKeyNotFound 键不存在错误

Functions

func CloseMemory

func CloseMemory()

CloseMemory 关闭内存缓存

func Del

func Del(keys ...string) error

Del 删除缓存

func Delete

func Delete(key string) error

Delete 删除缓存(别名)

func Expire

func Expire(key string, expiration time.Duration) error

Expire 设置过期时间

func Get

func Get(key string) (any, error)

Get 获取缓存值

func InitMemory

func InitMemory()

InitMemory 初始化内存缓存

func InitMemoryWithSize

func InitMemoryWithSize(maxSize int)

InitMemoryWithSize 初始化指定最大容量的内存缓存

func Keys

func Keys(pattern string) ([]string, error)

Keys 获取匹配的键(支持简单的 * 通配符)

func SAdd

func SAdd(key string, members ...any) error

SAdd 集合添加

func SCard

func SCard(key string) (int64, error)

SCard 获取集合大小

func Set

func Set(key string, value any, expiration time.Duration) error

Set 设置缓存(保持兼容原有签名)

Types

type MemoryCache

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

MemoryCache 内存缓存实现(支持 TTL、LRU 淘汰、定期清理)

Jump to

Keyboard shortcuts

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