cache

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 10, 2025 License: MIT Imports: 4 Imported by: 20

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ICache

type ICache interface {
	// Get 获取缓存值
	Get(ctx context.Context, key string) ([]byte, error)

	// Set 设置缓存值
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

	// Delete 删除缓存值
	Delete(ctx context.Context, key string) error

	// Exists 检查缓存是否存在
	Exists(ctx context.Context, key string) (bool, error)

	// Increment 对缓存值进行自增操作
	Increment(ctx context.Context, key string, value int64) (int64, error)

	// Decrement 对缓存值进行自减操作
	Decrement(ctx context.Context, key string, value int64) (int64, error)

	// Expire 设置缓存过期时间
	Expire(ctx context.Context, key string, expiration time.Duration) error
}

Cache 接口定义了缓存的基本操作

type MemoryCache

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

MemoryCache 是基于内存的 Cache 实现

func NewMemoryCache

func NewMemoryCache() *MemoryCache

NewMemoryCache 创建一个新的 MemoryCache 实例

func (*MemoryCache) Decrement

func (m *MemoryCache) Decrement(ctx context.Context, key string, value int64) (int64, error)

Decrement 实现 Cache 接口的 Decrement 方法

func (*MemoryCache) Delete

func (m *MemoryCache) Delete(ctx context.Context, key string) error

Delete 实现 Cache 接口的 Delete 方法

func (*MemoryCache) Exists

func (m *MemoryCache) Exists(ctx context.Context, key string) (bool, error)

Exists 实现 Cache 接口的 Exists 方法

func (*MemoryCache) Expire

func (m *MemoryCache) Expire(ctx context.Context, key string, expiration time.Duration) error

Expire 实现 Cache 接口的 Expire 方法

func (*MemoryCache) Get

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

Get 实现 Cache 接口的 Get 方法

func (*MemoryCache) Increment

func (m *MemoryCache) Increment(ctx context.Context, key string, value int64) (int64, error)

Increment 实现 Cache 接口的 Increment 方法

func (*MemoryCache) Set

func (m *MemoryCache) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

Set 实现 Cache 接口的 Set 方法

type RedisCache

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

RedisCache 是基于 Go Redis 的 Cache 实现

func NewRedisCache

func NewRedisCache(client *redis.Client) *RedisCache

NewRedisCache 创建一个新的 RedisCache 实例

func (*RedisCache) Decrement

func (r *RedisCache) Decrement(ctx context.Context, key string, value int64) (int64, error)

Decrement 实现 Cache 接口的 Decrement 方法

func (*RedisCache) Delete

func (r *RedisCache) Delete(ctx context.Context, key string) error

Delete 实现 Cache 接口的 Delete 方法

func (*RedisCache) Exists

func (r *RedisCache) Exists(ctx context.Context, key string) (bool, error)

Exists 实现 Cache 接口的 Exists 方法

func (*RedisCache) Expire

func (r *RedisCache) Expire(ctx context.Context, key string, expiration time.Duration) error

Expire 实现 Cache 接口的 Expire 方法

func (*RedisCache) Get

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

Get 实现 Cache 接口的 Get 方法

func (*RedisCache) Increment

func (r *RedisCache) Increment(ctx context.Context, key string, value int64) (int64, error)

Increment 实现 Cache 接口的 Increment 方法

func (*RedisCache) Set

func (r *RedisCache) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

Set 实现 Cache 接口的 Set 方法

Jump to

Keyboard shortcuts

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