cache

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Disabled = x.Disabled
	Fresh    = x.Fresh
)
View Source
const (
	LockTypeMemory int32 = iota
	LockTypeRedis
)

Variables

View Source
var (
	TTL               = x.TTL
	TTLFresh          = TTL(x.Fresh)
	TTLDisabled       = TTL(x.Disabled)
	Query             = x.Query
	DisableCacheUsage = x.DisableCacheUsage
	UseFreshData      = x.UseFreshData
)
View Source
var DBCacher = NewDBCacher()
View Source
var ErrFailedToAcquireLock = errors.New("failed to acquire lock")

Functions

func AddOptionParser

func AddOptionParser(adapter string, parser func(cache.Options) (cache.Options, error))

func AdminRefreshable

func AdminRefreshable(ctx echo.Context, customer *dbschema.OfficialCustomer, ttl x.GetOption) x.GetOption

func Cache

func Cache(ctx context.Context, args ...string) cache.Cache

func CacheNew

func CacheNew(ctx context.Context, opts cache.Options, keys ...string) error

func CloseCache added in v0.0.2

func CloseCache()

func Decr

func Decr(ctx context.Context, key string, args ...string) error

Decr 自减

func DefaultLockType

func DefaultLockType() int32

func Delete

func Delete(ctx context.Context, key string, args ...string) error

Delete 删除缓存

func Flush

func Flush(ctx context.Context, args ...string) error

Flush 删除所有缓存数据

func GenOptions

func GenOptions(ctx echo.Context, cacheSeconds int64) []x.GetOption

func Get

func Get(ctx context.Context, key string, recv interface{}, args ...string) error

Get 获取缓存

func Incr

func Incr(ctx context.Context, key string, args ...string) error

Incr 自增

func IsDbAccount

func IsDbAccount(v string) bool

func IsExist

func IsExist(ctx context.Context, key string, args ...string) (bool, error)

IsExist 是否存在缓存

func NewDBCacher

func NewDBCacher() factory.Cacher

func Put

func Put(ctx context.Context, key string, val interface{}, timeout int64, args ...string) error

Put 设置缓存

func RedisClient

func RedisClient() *redis.Client

func RedisMutex

func RedisMutex(key string, options ...redsync.Option) *redsync.Mutex

RedisMutex 分布式锁 example: mutex := RedisMutex(`goods_1`) err = mutex.Lock(ctx)

if err != nil {
	panic(err)
}

mutex.Unlock(ctx)

func RedisOptions

func RedisOptions() *redis.Options

func RedsyncClient

func RedsyncClient() *redsync.Redsync

func RegisterTryLocker

func RegisterTryLocker(t int32, fn TryLocker)

func SetDefaultLockType

func SetDefaultLockType(lockType int32)

func TTLIf added in v0.1.9

func TTLIf(condition bool, a x.GetOption, b x.GetOption) x.GetOption

func TTLIfCallback added in v0.1.9

func TTLIfCallback(condition func() bool, a x.GetOption, b x.GetOption) x.GetOption

func XFunc

func XFunc(ctx context.Context, key string, recv interface{}, fn func() error, options ...x.GetOption) error

XFunc 获取缓存,如果不存在则执行函数获取数据并缓存【自动避免缓存穿透】

func XQuery

func XQuery(ctx context.Context, key string, recv interface{}, query x.Querier, options ...x.GetOption) error

XQuery 获取缓存,如果不存在则执行函数获取数据并缓存【自动避免缓存穿透】

Types

type QueryFunc

type QueryFunc = x.QueryFunc

type TryLocker

type TryLocker interface {
	Lock(key string) (unlock UnlockFunc, err error)
	TryLock(key string) (unlock UnlockFunc, err error)
	TryLockWithTimeout(key string, timeout time.Duration) (unlock UnlockFunc, err error)
	TryLockWithContext(key string, ctx context.Context) (unlock UnlockFunc, err error)
}

type UnlockFunc

type UnlockFunc func() error

func Lock

func Lock(key string, types ...int32) (unlock UnlockFunc, err error)

func TryLock

func TryLock(key string, types ...int32) (unlock UnlockFunc, err error)

func TryLockWithContext

func TryLockWithContext(key string, ctx context.Context, types ...int32) (unlock UnlockFunc, err error)

func TryLockWithTimeout

func TryLockWithTimeout(key string, timeout time.Duration, types ...int32) (unlock UnlockFunc, err error)

Jump to

Keyboard shortcuts

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