Documentation
¶
Index ¶
- Constants
- Variables
- type CacheEntry
- type CacheUpdateMessage
- type DistributedCache
- type LocalCache
- type MultiCache
- func (c *MultiCache) DelWithPubSub(ctx context.Context, keys ...string) error
- func (c *MultiCache) DelWithVersion(ctx context.Context, keys []string, vrs []int64) error
- func (c *MultiCache) GetData(data []byte) []byte
- func (c *MultiCache) GetDistributedCache() *DistributedCache
- func (c *MultiCache) GetInPubSub(ctx context.Context, key string) ([]byte, error)
- func (c *MultiCache) GetLocalCache() *LocalCache
- func (c *MultiCache) GetVersion(data []byte) int64
- func (c *MultiCache) GetVersionInString(data string) int64
- func (c *MultiCache) SetWithPubSub(ctx context.Context, key string, value []byte) error
- func (c *MultiCache) SetWithVersion(ctx context.Context, key string, val []byte, version int64) error
- func (c *MultiCache) Stats() bigcache.Stats
- func (c *MultiCache) SubscribeUpdate(ctx context.Context)
- type OptionFunc
Constants ¶
View Source
const ( VersionStr = "vrs" DataStr = "data" KeyStr = "key" ExpireStr = "exp" ActionStr = "act" )
View Source
const (
CacheChannel = "cache-channel"
)
Variables ¶
View Source
var ( ErrRecordNotFound = errors.New("缓存记录不存在") ErrBadExpireTime = errors.New("分布式缓存的过期时间不得早于本地缓存") ErrDeleteKeyFailed = errors.New("key删除失败") ErrSetKeyFailed = errors.New("key设置失败") ErrBadMultiCache = errors.New("multiCache暂不可用") ErrDirtyData = errors.New("读入的数据为脏数据") ErrMarshalFailed = errors.New("marshal 失败") ErrUnmarshalFailed = errors.New("unmarshal 失败") )
Functions ¶
This section is empty.
Types ¶
type CacheEntry ¶
type CacheUpdateMessage ¶
type CacheUpdateMessage struct {
Key string `json:"key"`
Action string `json:"act"`
Data []byte `json:"data,omitempty"`
Version int64 `json:"vrs"`
}
func (CacheUpdateMessage) MarshalJSON ¶
func (c CacheUpdateMessage) MarshalJSON() ([]byte, error)
逻辑跟joinMdData一样
func (*CacheUpdateMessage) UnmarshalJSON ¶
func (c *CacheUpdateMessage) UnmarshalJSON(data []byte) error
type DistributedCache ¶
type DistributedCache struct {
*redis.ClusterClient
}
func MustNewDistributedCache ¶
func MustNewDistributedCache(conf *redis.ClusterOptions) *DistributedCache
type LocalCache ¶
func MustNewLocalCache ¶
func MustNewLocalCache(conf *bigcache.Config) *LocalCache
type MultiCache ¶
type MultiCache struct {
EnableTracing bool
//该Expire只能为distributedCache设置,localCache的超时一旦设置之后无法改变
ExpireTime time.Duration
//redlock *redlock.RedLock
//使用版本控制将带来更高的一致性,但是需要Set系列的函数传入的data是可以得到version字段的
UseVersionControll bool
RocketmqConsumer rocketmq.PushConsumer
//这个mtx只是保证本地缓存更新时是一致的,防止老版本更新慢于新版本更新
Mtx *sync.RWMutex
Logger *otelzap.SugaredLogger
// contains filtered or unexported fields
}
func MustNewMultiCache ¶
func MustNewMultiCache(dc *redis.ClusterOptions, lc *bigcache.Config, opts ...OptionFunc) *MultiCache
默认会将使用的分布式缓存作为分布式锁
func (*MultiCache) DelWithPubSub ¶
func (c *MultiCache) DelWithPubSub(ctx context.Context, keys ...string) error
TODO: 后续可以在返回error里记录哪几个区间的key没被删除成功
func (*MultiCache) DelWithVersion ¶
func (*MultiCache) GetData ¶
func (c *MultiCache) GetData(data []byte) []byte
func (*MultiCache) GetDistributedCache ¶
func (c *MultiCache) GetDistributedCache() *DistributedCache
func (*MultiCache) GetInPubSub ¶
func (*MultiCache) GetLocalCache ¶
func (c *MultiCache) GetLocalCache() *LocalCache
func (*MultiCache) GetVersion ¶
func (c *MultiCache) GetVersion(data []byte) int64
默认情况下如果没有version字段则默认认为字段version为0
func (*MultiCache) GetVersionInString ¶
func (c *MultiCache) GetVersionInString(data string) int64
与getVersion无异,只是参数换为string
func (*MultiCache) SetWithPubSub ¶
func (*MultiCache) SetWithVersion ¶
func (*MultiCache) Stats ¶
func (c *MultiCache) Stats() bigcache.Stats
func (*MultiCache) SubscribeUpdate ¶
func (c *MultiCache) SubscribeUpdate(ctx context.Context)
type OptionFunc ¶
type OptionFunc func(*MultiCache)
func WithExpireTime ¶
func WithExpireTime(t time.Duration) OptionFunc
func WithVersionControl ¶
func WithVersionControl(enable bool) OptionFunc
Click to show internal directories.
Click to hide internal directories.