Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
DefaultCodec = jsoniter.ConfigCompatibleWithStandardLibrary
)
View Source
var DefaultSpinMutexConfig = SpinMutexConfig{ Retry: 3, Sleep: 100 * time.Millisecond, Timeout: 500 * time.Millisecond, }
DefaultSpinMutexConfig 默认一份自旋锁配置
Functions ¶
Types ¶
type Cache ¶
type Cache interface { // Get 读取缓存, i 是读出的数据,必须是一个指针 Get(ctx context.Context, i interface{}) error // Delete 删除缓存 Delete(ctx context.Context) error // SetCodec 设置序列化协议 SetCodec(c Codec) // SetLoadHandler 设置加载函数 SetLoadHandler(h LoadHandler) }
Cache 定义一个缓存的操作
type Codec ¶
type Codec interface { // Unmarshal 反序列化 Unmarshal(data []byte, v interface{}) error // Marshal 序列化 Marshal(v interface{}) ([]byte, error) }
Codec 是缓存结构序列化的抽象定义
type LoadHandler ¶
LoadHandler 是 Get获取不到缓存时,应该调用的加载的函数
type SpinMutex ¶
type SpinMutex struct {
// contains filtered or unexported fields
}
SpinLock 自旋锁
func NewSpinMutex ¶
func NewSpinMutex(client redis.UniversalClient, key string, config SpinMutexConfig) *SpinMutex
NewSpinLock 创建一个重试锁
type SpinMutexConfig ¶
type SpinMutexConfig struct { Retry int // 重试次数 Sleep time.Duration // 每次等待时间 Timeout time.Duration // 持有锁最长时间 }
SpinMutexConfig 自旋锁配置 * Retry 定义锁重试次数,到达次数还无法获得锁,则抛出retry to out * Sleep 每次重试后,阻塞时间,建议不要太长 * Timout 持有锁的最长时间,即每次事务最长执行时间
type StringCache ¶
type StringCache struct { Codec Codec // 序列化协议 LoadHandler LoadHandler // 加载函数 // contains filtered or unexported fields }
StringCache 使用redis的string结构作缓存的结构体
func (*StringCache) Get ¶
func (s *StringCache) Get(ctx context.Context, i interface{}) error
Get 读取缓存
func (*StringCache) SetLoadHandler ¶
func (s *StringCache) SetLoadHandler(h LoadHandler)
SetLoadHandler 设置LoadHandler
Click to show internal directories.
Click to hide internal directories.