cache

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cache

func Cache(opts ...Option) middleware.Middleware

Cache 返回一个缓存中间件

Types

type CacheStore

type CacheStore interface {
	// Get 获取缓存值
	Get(key string) (interface{}, bool)
	// Set 设置缓存值
	Set(key string, value interface{}, ttl time.Duration)
	// Delete 删除缓存值
	Delete(key string)
}

CacheStore 缓存存储接口

type KeyGenerator

type KeyGenerator func(ctx context.Context, req interface{}) string

KeyGenerator 定义缓存键生成函数类型

type Option

type Option func(*options)

Option 是缓存中间件的选项

func WithKeyGenerator

func WithKeyGenerator(gen KeyGenerator) Option

WithKeyGenerator 设置缓存键生成器

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger 设置日志记录器

func WithMaxSize

func WithMaxSize(size int) Option

WithMaxSize 设置缓存最大条目数

func WithStore

func WithStore(store CacheStore) Option

WithStore 设置缓存存储实现

func WithTTL

func WithTTL(ttl time.Duration) Option

WithTTL 设置缓存过期时间

Jump to

Keyboard shortcuts

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