cache

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IBoolCacher added in v1.0.2

type IBoolCacher interface {
	ICloser
	GetBool(ctx context.Context, key string) (bool, error)
	SetBool(ctx context.Context, key string, value bool, expiration time.Duration) error
}

IBoolCacher 布尔缓存

type ICacher

type ICacher interface {
	ISimpleCacher
	IIntCacher
	IFloatCacher
	IObjectCacher
	IBoolCacher
	IKeyPrefixCacher
	// SetNX 设置缓存,如果key存在则返回false
	SetNX(ctx context.Context, key string, value string, expiration time.Duration) (bool, error)
}

ICacher 缓存

func NewFreeCache added in v1.0.2

func NewFreeCache(cli *freecache.Cache) ICacher

NewFreeCache 创建一个默认的缓存

func NewNutsDbCacher added in v1.0.2

func NewNutsDbCacher(client *nutsdb.DB, bucket string) ICacher

NewNutsDbCacher creates a new nutsdb cache client.

func NewRedisCacher added in v1.0.2

func NewRedisCacher(cli *redis.Client) ICacher

NewRedisCacher creates a new redis cacher

type ICloser added in v1.0.2

type ICloser interface {
	Close() error
}

ICloser 关闭缓存

type IFloatCacher added in v1.0.2

type IFloatCacher interface {
	ICloser
	GetFloat64(ctx context.Context, key string) (float64, error)
	SetFloat64(ctx context.Context, key string, value float64, expiration time.Duration) error
}

IFloatCacher 浮点数缓存

type IIntCacher added in v1.0.2

type IIntCacher interface {
	ICloser
	// Inc 增加缓存值
	Inc(ctx context.Context, key string, expiration time.Duration) (int64, error)
	// Dec 减少缓存值
	Dec(ctx context.Context, key string, expiration time.Duration) (int64, error)
	// IncMax 增加缓存值,如果超过max则返回max
	IncMax(ctx context.Context, key string, max int64, expiration time.Duration) (bool, error)
	// DecMin 减少缓存值,如果小于min则返回min
	DecMin(ctx context.Context, key string, min int64, expiration time.Duration) (bool, error)
	// GetInt64 获取缓存
	GetInt64(ctx context.Context, key string) (int64, error)
	// SetInt64 设置缓存
	SetInt64(ctx context.Context, key string, value int64, expiration time.Duration) error
}

IIntCacher 整数缓存

type IKeyPrefixCacher added in v1.1.0

type IKeyPrefixCacher interface {
	ICloser
	// Keys 获取带前缀的缓存key
	Keys(ctx context.Context, prefix string) ([]string, error)
	// DelKeys 删除带前缀的缓存key
	DelKeys(ctx context.Context, prefix string) error
}

IKeyPrefixCacher 带前缀的缓存

type IObjectCacher added in v1.0.2

type IObjectCacher interface {
	ICloser
	// GetObject 获取缓存
	GetObject(ctx context.Context, key string, obj IObjectSchema) error
	// SetObject 设置缓存
	SetObject(ctx context.Context, key string, obj IObjectSchema, expiration time.Duration) error
}

IObjectCacher 对象缓存

type IObjectSchema added in v1.0.2

type IObjectSchema interface {
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
}

IObjectSchema 缓存对象

type ISimpleCacher added in v1.0.2

type ISimpleCacher interface {
	ICloser
	// Delete 删除缓存
	Delete(ctx context.Context, key string) error
	// Exist 判断缓存是否存在
	Exist(ctx context.Context, key string) (bool, error)
	// Get 获取缓存
	Get(ctx context.Context, key string) (string, error)
	// Set 设置缓存
	Set(ctx context.Context, key string, value string, expiration time.Duration) error
}

ISimpleCacher 简单缓存

Jump to

Keyboard shortcuts

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