cache

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyExpired  = errors.New("key expired")
	ErrKeyNotExist = errors.New("key not exist")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	IsExist(key string) bool
	Get(key string) (string, error)
	Put(key string, value string, expiration time.Duration) error
	Delete(key string) error
	BatchDelete(prefix string) error
}

Cache 缓存接口

func NewCache

func NewCache() (Cache, error)

NewCache 创建缓存实例

func NewMemoryCache

func NewMemoryCache() Cache

func NewRedisWithClient

func NewRedisWithClient(redisClient redis.UniversalClient, keyPrefix string) Cache

NewRedisWithClient 使用redis连接创建缓存实例

type MemoryCache

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

MemoryCache 内存缓存

func (*MemoryCache) BatchDelete

func (c *MemoryCache) BatchDelete(prefix string) error

BatchDelete 批量删除

func (*MemoryCache) Delete

func (c *MemoryCache) Delete(key string) error

Delete 删除删除项

func (*MemoryCache) Get

func (c *MemoryCache) Get(key string) (string, error)

Get 获取缓存项

func (*MemoryCache) IsExist

func (c *MemoryCache) IsExist(key string) bool

IsExist 缓存项是否存在

func (*MemoryCache) Put

func (c *MemoryCache) Put(key string, value string, expiration time.Duration) error

Put 设置缓存项

type Redis

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

Redis redis缓存

func (*Redis) BatchDelete

func (redis *Redis) BatchDelete(prefix string) error

BatchDelete 批量删除

func (*Redis) Delete

func (redis *Redis) Delete(key string) error

func (*Redis) Get

func (redis *Redis) Get(key string) (string, error)

func (*Redis) IsExist

func (redis *Redis) IsExist(key string) bool

func (*Redis) Put

func (redis *Redis) Put(key string, value string, expiration time.Duration) error

Jump to

Keyboard shortcuts

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