Documentation
¶
Index ¶
- func UnsafeBytes(s string) []byte
- func UnsafeString(b []byte) string
- type Cacheable
- type Handler
- type Store
- type Wrapper
- func (w *Wrapper) Clear(ctx context.Context, prefix string) error
- func (w *Wrapper) Delete(ctx context.Context, keys ...string) error
- func (w *Wrapper) DeleteByModels(ctx context.Context, models ...Cacheable) error
- func (w *Wrapper) Exists(ctx context.Context, key string) (bool, error)
- func (w *Wrapper) Get(ctx context.Context, key string, target interface{}) (bool, error)
- func (w *Wrapper) GetBytes(ctx context.Context, key string) ([]byte, error)
- func (w *Wrapper) GetOrLoad(ctx context.Context, key string, ttl time.Duration, target interface{}, ...) error
- func (w *Wrapper) Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error
- func (w *Wrapper) SetBytes(ctx context.Context, key string, value []byte, ttl time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Handler ¶
type Handler interface {
Get(key []byte) ([]byte, error)
Set(key, value []byte) error
SetWithTTL(key, value []byte, ttl time.Duration) error
Del(keys ...[]byte) error
Exists(key []byte) (bool, error)
}
Handler 缓存处理器接口(字节级别操作)
type Store ¶
type Store interface {
// Get 获取缓存值
Get(ctx context.Context, key string) (string, error)
// Set 设置缓存值
Set(ctx context.Context, key string, value string, ttl time.Duration) error
// Delete 删除缓存
Delete(ctx context.Context, key string) error
// Exists 检查缓存是否存在
Exists(ctx context.Context, key string) (bool, error)
// Clear 清除所有缓存(按前缀)
Clear(ctx context.Context, prefix string) error
}
Store 缓存存储接口
type Wrapper ¶ added in v0.1.1
type Wrapper struct {
// contains filtered or unexported fields
}
Wrapper 缓存包装器,用于 Repository 层的缓存操作
func NewWrapper ¶ added in v0.1.1
NewWrapper 创建缓存包装器
func (*Wrapper) DeleteByModels ¶ added in v0.1.1
DeleteByModels 根据可缓存模型删除缓存
func (*Wrapper) GetOrLoad ¶ added in v0.1.1
func (w *Wrapper) GetOrLoad(ctx context.Context, key string, ttl time.Duration, target interface{}, loadFn func() (interface{}, error)) error
GetOrLoad 获取缓存,如果不存在则执行加载函数
Click to show internal directories.
Click to hide internal directories.