store

package
v0.0.0-...-a0a356d Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(cap uint16) *cache

func Now

func Now() int64

返回 clock 变量的当前值。atomic.LoadInt64 是原子操作,用于保证在多线程/协程环境中安全地读取 clock 变量的值

Types

type CacheType

type CacheType string

CacheType 缓存类型

const (
	LRU  CacheType = "lru"
	LRU2 CacheType = "lru2"
)

type Options

type Options struct {
	MaxBytes        int64  // 最大的缓存字节数(用于 lru)
	BucketCount     uint16 // 缓存的桶数量(用于 lru-2)
	CapPerBucket    uint16 // 每个桶的容量(用于 lru-2)
	Level2Cap       uint16 // lru-2 中二级缓存的容量(用于 lru-2)
	CleanupInterval time.Duration
	OnEvicted       func(key string, value Value)
}

Options 通用缓存配置选项

func NewOptions

func NewOptions() Options

type Store

type Store interface {
	Get(key string) (Value, bool)
	Set(key string, value Value) error
	SetWithExpiration(key string, value Value, expiration time.Duration) error
	Delete(key string) bool
	Clear()
	Len() int
	Close()
}

Store 缓存接口

func NewStore

func NewStore(cacheType CacheType, opts Options) Store

NewStore 创建缓存存储实例

type Value

type Value interface {
	Len() int // 返回数据大小
}

Value 缓存值接口

Jump to

Keyboard shortcuts

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