common

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CacheEmptyValue = "" // 空缓存值

Functions

func CheckCacheBase

func CheckCacheBase(base CacheBase)

func CheckCacheInfo

func CheckCacheInfo(cacheInfo interface{}) error

func CheckHashSubKey

func CheckHashSubKey(subKey string)

Types

type CacheBase

type CacheBase struct {
	Key     string        // 缓存的Key
	ExpTime time.Duration // key的过期时间
}

func NewCacheBase

func NewCacheBase(key string, exp time.Duration) *CacheBase

type HashCache

type HashCache struct {
	CacheBase
	SubKey string // 子key,对应hash中的field
}

func NewHashCache

func NewHashCache(key, subKey string, expTime time.Duration) *HashCache

func (*HashCache) BaseInfo

func (c *HashCache) BaseInfo() CacheBase

func (*HashCache) UpdateCacheKey

func (c *HashCache) UpdateCacheKey(key string)

type HotKeyOption

type HotKeyOption struct {
	// contains filtered or unexported fields
}

HotKeyOption 热key处理选项

func NewHotKeyOption

func NewHotKeyOption(opts ...HotKeyOptionWrap) (*HotKeyOption, error)

func (*HotKeyOption) GetFromLocalCache

func (o *HotKeyOption) GetFromLocalCache() (string, error)

func (*HotKeyOption) GetShardingKey

func (o *HotKeyOption) GetShardingKey() string

func (*HotKeyOption) IsHotKey

func (o *HotKeyOption) IsHotKey() bool

func (*HotKeyOption) SetToLocalCache

func (o *HotKeyOption) SetToLocalCache(v string) error

func (*HotKeyOption) UseLocalCache

func (o *HotKeyOption) UseLocalCache() bool

UseLocalCache 当需要解决热key问题时,优先考虑使用本地缓存

type HotKeyOptionWrap

type HotKeyOptionWrap func(o *HotKeyOption)

func WithGetShardingKey

func WithGetShardingKey(f func() string) HotKeyOptionWrap

func WithIsHotKey

func WithIsHotKey(f func() bool) HotKeyOptionWrap

func WithLocalCache

func WithLocalCache(localCache ILocalCache, cacheInfo *CacheBase) HotKeyOptionWrap

type ICacheInfo

type ICacheInfo interface {
	BaseInfo() CacheBase
	UpdateCacheKey(key string)
}

type ILocalCache

type ILocalCache interface {
	// Get 如果数据不存在,则会返回ErrLocalCacheNoData错误
	Get(key string) (string, error)
	Set(cacheInfo *CacheBase, value string) error
	Del(key string) error
}

ILocalCache 本地缓存抽象,主要用于解决hot key

func NewWrapBigCache

func NewWrapBigCache(bigCache *bigcache.BigCache) ILocalCache

func NewWrapGoCache

func NewWrapGoCache(cache *goCache.Cache) ILocalCache

type MSetModel

type MSetModel struct {
	*StringCache
	Value string
}

MSetModel 批量设置string缓存时的对象信息

func NewMSetModel

func NewMSetModel(key, value string, expTime time.Duration) *MSetModel

type StringCache

type StringCache struct {
	CacheBase
}

func NewStringCache

func NewStringCache(key string, expTime time.Duration) *StringCache

func (*StringCache) BaseInfo

func (c *StringCache) BaseInfo() CacheBase

func (*StringCache) UpdateCacheKey

func (c *StringCache) UpdateCacheKey(key string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL