Documentation
¶
Index ¶
- Variables
- type Cachex
- func (c *Cachex) Del(ctx context.Context, keys ...interface{}) error
- func (c *Cachex) Get(ctx context.Context, key, value interface{}, opts ...GetOption) error
- func (c *Cachex) Set(ctx context.Context, key, value interface{}) error
- func (c *Cachex) SetWithTTL(ctx context.Context, key, value interface{}, TTL time.Duration) error
- func (c *Cachex) UseStaleWhenError(use bool)
- type ClearableStorage
- type DeletableStorage
- type Expired
- type GetOption
- type Keyable
- type NopStorage
- func (NopStorage) Clear(ctx context.Context) error
- func (NopStorage) Del(ctx context.Context, keys ...interface{}) error
- func (NopStorage) Get(ctx context.Context, key, value interface{}) error
- func (NopStorage) Set(ctx context.Context, key, value interface{}) error
- func (NopStorage) SetWithTTL(ctx context.Context, key, value interface{}, TTL time.Duration) error
- type NotFound
- type Querier
- type QueryFunc
- type Sentinel
- type SetWithTTLableStorage
- type Storage
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound 没找到 ErrNotFound = errors.New("not found") // ErrNotSupported 操作不支持 ErrNotSupported = errors.New("not supported operation") )
var ErrNoResult = errors.New("no result")
ErrNoResult 无结果错误。 消费者等待到的结果无value无err时(生产者panic或编码错误),将会得到该错误。
Functions ¶
This section is empty.
Types ¶
type Cachex ¶
type Cachex struct {
// contains filtered or unexported fields
}
Cachex 缓存处理类
func (*Cachex) SetWithTTL ¶
SetWithTTL 更新,并定制TTL
func (*Cachex) UseStaleWhenError ¶
UseStaleWhenError 设置当查询发生错误时,使用过期的缓存数据。该特性需要Storage支持(Get返回过期的缓存数据和Expired错误实现)。默认关闭。
type ClearableStorage ¶
ClearableStorage 支持清理操作的存储后端接口
type DeletableStorage ¶
DeletableStorage 支持删除操作的存储后端接口
type GetOption ¶
type GetOption struct {
// contains filtered or unexported fields
}
GetOption Get方法的可选参数项结构,不需要直接调用。
func GetTTLOption ¶
GetTTLOption 为Get操作定制TTL。 需要存储后端支持,否则报错。
type Keyable ¶
type Keyable interface {
// Key 给Storage的缓存Key
CacheKey() interface{}
}
Keyable 如果需要包装多个参数为key,包装结构体实现该接口,以支持获取包装结构体的缓存Key。
type NopStorage ¶
type NopStorage struct { }
NopStorage 一个什么都不干的存储后端。 可以用NopStorage加CacheX组合出一个单实例内不重复查询的机制。
func (NopStorage) Clear ¶
func (NopStorage) Clear(ctx context.Context) error
Clear 实现ClearableStorage接口,只返回nil。
func (NopStorage) Del ¶
func (NopStorage) Del(ctx context.Context, keys ...interface{}) error
Del 实现DeletableStorage接口,只返回nil。
func (NopStorage) Get ¶
func (NopStorage) Get(ctx context.Context, key, value interface{}) error
Get 实现Storage接口,只返回NotFound错误。
func (NopStorage) Set ¶
func (NopStorage) Set(ctx context.Context, key, value interface{}) error
Set 实现Storage接口,只返回nil。
func (NopStorage) SetWithTTL ¶
SetWithTTL 实现SetWithTTLableStorage接口,只返回nil。
type NotFound ¶
type NotFound interface { error NotFound() }
NotFound 没找到错误接口。 需要存储后端找不到缓存时,返回一个实现了NotFound接口的错误。
type Querier ¶
type Querier interface { // Query 查询。value必须是非nil指针。没找到返回NotFound错误实现 Query(ctx context.Context, request, value interface{}) error }
Querier 查询接口
type Sentinel ¶
type Sentinel struct {
// contains filtered or unexported fields
}
Sentinel 哨兵。一个生产者,多个消费者等待生产者完成并提交结果
Directories
¶
Path | Synopsis |
---|---|
Package mock_cachex is a generated GoMock package.
|
Package mock_cachex is a generated GoMock package. |