Documentation
¶
Overview ¶
Package cache is a package that unifies the definition of caching, supporting both redis and local caching.
Index ¶
Constants ¶
View Source
const ( // cache prefix key, must end with a colon CacheNameExampleCachePrefixKeyLock = "lock:prefixKeyExample:" CacheNameExampleCachePrefixKey = "data:prefixKeyExample:" // CacheNameExampleExpireTime expire time CacheNameExampleExpireTime = 30 * time.Minute )
View Source
const ( // cache prefix key, must end with a colon UserExampleCachePrefixKeyLock = "lock:userExample:" UserExampleCachePrefixKey = "data:userExample:" // UserExampleExpireTime expire time UserExampleExpireTime = 30 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheNameExample ¶ added in v1.4.22
type CacheNameExample interface {
GetLoopLock(ctx context.Context, key string, options ...redsync.Option) (*redsync.Mutex, error)
GetLock(ctx context.Context, key string, options ...redsync.Option) (*redsync.Mutex, error)
// 封装了锁的获取、看门狗自动续期、业务执行及释放逻辑
WatchDogLock(ctx context.Context, key string, expiry time.Duration, task func(ctx context.Context) error, options ...redsync.Option) error
WatchDogLoopLock(ctx context.Context, key string, expiry time.Duration, task func(ctx context.Context) error, options ...redsync.Option) error
Set(ctx context.Context, key string, data interface{}, duration time.Duration) error
Get(ctx context.Context, key string) (interface{}, error)
GetIdByKey(ctx context.Context, key string) (id string, err error)
Del(ctx context.Context, key string) error
DelByPrefix(ctx context.Context, prefix string) error
DelByKey(ctx context.Context, key string) error
SetPlaceholder(ctx context.Context, key string) error
SetPlaceholderByKey(ctx context.Context, key string) error
IsPlaceholderErr(err error) bool
GetCacheName(ctx context.Context, keyNameExample keyTypeExample) (valueTypeExample, error)
SetCacheName(ctx context.Context, keyNameExample keyTypeExample, data valueTypeExample, duration time.Duration) error
DelCacheName(ctx context.Context, keyNameExample keyTypeExample) error
}
CacheNameExample cache interface
func NewCacheNameExample ¶ added in v1.4.22
func NewCacheNameExample(cacheType *database.CacheType) CacheNameExample
NewCacheNameExample new a cache
type UserExampleCache ¶
type UserExampleCache interface {
GetLoopLock(ctx context.Context, key string, options ...redsync.Option) (*redsync.Mutex, error)
GetLock(ctx context.Context, key string, options ...redsync.Option) (*redsync.Mutex, error)
// 封装了锁的获取、看门狗自动续期、业务执行及释放逻辑
WatchDogLock(ctx context.Context, key string, expiry time.Duration, task func(ctx context.Context) error, options ...redsync.Option) error
WatchDogLoopLock(ctx context.Context, key string, expiry time.Duration, task func(ctx context.Context) error, options ...redsync.Option) error
Set(ctx context.Context, id uint64, data *model.UserExample, duration time.Duration) error
SetIdByKey(ctx context.Context, key string, id uint64, duration time.Duration) error
SetIdsByKey(ctx context.Context, key string, ids []uint64, duration time.Duration) error
Get(ctx context.Context, id uint64) (*model.UserExample, error)
GetIdByKey(ctx context.Context, key string) (id uint64, err error)
GetIdsByKey(ctx context.Context, key string) (ids []uint64, err error)
MultiGet(ctx context.Context, ids []uint64) (map[uint64]*model.UserExample, error)
MultiSet(ctx context.Context, data []*model.UserExample, duration time.Duration) error
Del(ctx context.Context, id uint64) error
DelByPrefix(ctx context.Context, prefix string) error
DelByKey(ctx context.Context, key string) error
SetPlaceholder(ctx context.Context, id uint64) error
SetPlaceholderByKey(ctx context.Context, key string) error
IsPlaceholderErr(err error) bool
}
UserExampleCache cache interface
func NewUserExampleCache ¶
func NewUserExampleCache(cacheType *database.CacheType) UserExampleCache
NewUserExampleCache new a cache
Click to show internal directories.
Click to hide internal directories.