local

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 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 Option

type Option func(*config)

Option 配置本地缓存。

func WithDefaultTTL

func WithDefaultTTL(ttl time.Duration) Option

WithDefaultTTL 设置调用方未指定 TTL 时使用的默认有效期。

func WithSize

func WithSize(size int) Option

WithSize 设置预分配缓存大小,单位为字节。

type Store

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

Store 是基于 FreeCache 的缓存实现。

func New

func New(opts ...Option) *Store

New 创建本地缓存。

func (*Store) Close

func (s *Store) Close() error

Close 清空本地缓存。

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

Delete 删除缓存值。

func (*Store) EntryCount

func (s *Store) EntryCount() int64

EntryCount 返回当前缓存项数量。

func (*Store) EvacuateCount

func (s *Store) EvacuateCount() int64

EvacuateCount 返回被覆盖或淘汰的缓存项数量。

func (*Store) ExpiredCount

func (s *Store) ExpiredCount() int64

ExpiredCount 返回已经过期的缓存项数量。

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) ([]byte, error)

Get 获取缓存值。

func (*Store) GetDel

func (s *Store) GetDel(ctx context.Context, key string) ([]byte, error)

GetDel 原子读取并删除缓存值。

func (*Store) GetMulti

func (s *Store) GetMulti(ctx context.Context, keys []string) ([][]byte, error)

GetMulti 按输入顺序批量获取缓存值。

func (*Store) Has

func (s *Store) Has(ctx context.Context, key string) (bool, error)

Has 判断缓存键是否存在。

func (*Store) HitCount

func (s *Store) HitCount() int64

HitCount 返回缓存命中次数。

func (*Store) MissCount

func (s *Store) MissCount() int64

MissCount 返回缓存未命中次数。

func (*Store) Set

func (s *Store) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error

Set 写入缓存值。

func (*Store) SetMulti

func (s *Store) SetMulti(ctx context.Context, items []store.Item) error

SetMulti 批量写入缓存值。

func (*Store) SetNX

func (s *Store) SetNX(ctx context.Context, key string, value []byte, ttl time.Duration) (bool, error)

SetNX 在键不存在时原子写入缓存值。

Jump to

Keyboard shortcuts

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