Documentation ¶
Index ¶
- Variables
- func BuildCacheKey(keyPrefix string, key string) (cacheKey string, err error)
- func Del(ctx context.Context, keys ...string) error
- func Get(ctx context.Context, key string, val interface{}) error
- func MultiGet(ctx context.Context, keys []string, valueMap interface{}) error
- func MultiSet(ctx context.Context, valMap map[string]interface{}, expiration time.Duration) error
- func Set(ctx context.Context, key string, val interface{}, expiration time.Duration) error
- func SetCacheWithNotFound(ctx context.Context, key string) error
- type Cache
- type GetFunc
- type Getter
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultExpireTime 默认过期时间 DefaultExpireTime = time.Hour * 24 // DefaultNotFoundExpireTime 结果为空时的过期时间 1分钟, 常用于数据为空时的缓存时间(缓存穿透) DefaultNotFoundExpireTime = time.Minute // NotFoundPlaceholder . NotFoundPlaceholder = "*" // DefaultClient 生成一个缓存客户端,其中keyPrefix 一般为业务前缀 DefaultClient Cache // ErrPlaceholder . ErrPlaceholder = errors.New("cache: placeholder") // ErrSetMemoryWithNotFound . ErrSetMemoryWithNotFound = errors.New("cache: set memory cache err for not found") )
Functions ¶
func BuildCacheKey ¶
BuildCacheKey 构建一个带有前缀的缓存key
Types ¶
type Cache ¶
type Cache interface { Set(ctx context.Context, key string, val interface{}, expiration time.Duration) error Get(ctx context.Context, key string, val interface{}) error MultiSet(ctx context.Context, valMap map[string]interface{}, expiration time.Duration) error MultiGet(ctx context.Context, keys []string, valueMap interface{}) error Del(ctx context.Context, keys ...string) error SetCacheWithNotFound(ctx context.Context, key string) error }
Cache 定义cache驱动接口
func NewMemoryCache ¶
NewMemoryCache create a memory cache
Click to show internal directories.
Click to hide internal directories.