Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
// 基础操作
IsExist(ctx context.Context, key string) bool
Get(ctx context.Context, key string) (string, error)
Put(ctx context.Context, key string, value string, expiration time.Duration) error
Delete(ctx context.Context, key string) error
BatchDelete(ctx context.Context, prefix string) error
// 高级操作
GetWithTTL(ctx context.Context, key string) (string, time.Duration, error)
Increment(ctx context.Context, key string, delta int64) (int64, error)
Decrement(ctx context.Context, key string, delta int64) (int64, error)
SetNX(ctx context.Context, key string, value string, expiration time.Duration) (bool, error)
Expire(ctx context.Context, key string, expiration time.Duration) error
Keys(ctx context.Context, pattern string) ([]string, error)
FlushAll(ctx context.Context) error
// 生命周期
Close() error
}
Cache 基础缓存接口
type CacheStrategy ¶
type CacheStrategy interface {
// ShouldCache 是否应该缓存
ShouldCache(key string, value interface{}) bool
// GetTTL 获取TTL
GetTTL(key string, value interface{}) time.Duration
// GetCacheKey 获取缓存键
GetCacheKey(prefix string, parts ...string) string
// ShouldWarmUp 是否启用预热
ShouldWarmUp() bool
}
CacheStrategy 缓存策略接口
Click to show internal directories.
Click to hide internal directories.