memolock

package
v0.0.0-...-79be558 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheNotFound = errors.New("Key not found")

ErrCacheNotFound happens when cache with certain key not exist

View Source
var ErrClosing = errors.New("Operation canceled by Close()")

ErrClosing happens when calling Close(), all pending requests will be failed with this error

View Source
var ErrLockRenew = errors.New("Unable to renew the lock")

ErrLockRenew happens when trying to renew a lock that expired already

View Source
var ErrTimeOut = errors.New("Operation Timed Out")

ErrTimeOut happens when the given timeout expires

Functions

func InitLocalCache

func InitLocalCache(cfg *ristretto.Config)

Types

type ExternalFetchFunc

type ExternalFetchFunc = func() error

ExternalFetchFunc has the same purpose as FetchFunc but works on the assumption that the value will be set in Redis and notificed on Pub/Sub by an external program

type FetchFunc

type FetchFunc = func() (string, time.Duration, error)

FetchFunc is the function that the caller should provide to compute the value if not present in Redis already. time.Duration defines for how long the value should be cached in Redis.

type LockRenewFunc

type LockRenewFunc = func(time.Duration) error

LockRenewFunc is the function that RenewableFetchFunc will get as input and that must be called to extend a locks' life

type MemoLockConfig

type MemoLockConfig struct {
	NumCounters int64 `json:"numCounter" default:"1e4"`
	MaxCost     int64 `json:"maxCost" default:"1e4"`
	BufferItems int64 `json:"bufferItems" default:"64"`
}

type RedisMemoLock

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

RedisMemoLock implements the "promise" mechanism

func NewRedisMemoLock

func NewRedisMemoLock(ctx context.Context, client *redis.Client, resourceTag string, lockTimeout time.Duration) (*RedisMemoLock, error)

NewRedisMemoLock Creates a new RedisMemoLock instance

func (*RedisMemoLock) Close

func (r *RedisMemoLock) Close()

Close stops listening to Pub/Sub and resolves all pending subscriptions with ErrClosing.

func (*RedisMemoLock) GetResource

func (r *RedisMemoLock) GetResource(ctx context.Context, resID string, timeout time.Duration, generatingFunc FetchFunc, localCacheMult float64) (string, error)

func (*RedisMemoLock) GetResourceExternal

func (r *RedisMemoLock) GetResourceExternal(ctx context.Context, resID string, timeout time.Duration, generatingFunc ExternalFetchFunc) (string, error)

GetResourceExternal assumes that the value will be set on Redis and notified on Pub/Sub by another program. Useful for when generatingFunc launches an executable instead of doing the work in the current context.

func (*RedisMemoLock) GetResourceRenewable

func (r *RedisMemoLock) GetResourceRenewable(ctx context.Context, resID string, timeout time.Duration, generatingFunc RenewableFetchFunc) (string, error)

GetResourceRenewable has the same purpose as GetResource but allows the caller to extend the lock lease during the execution of generatingFunc

func (*RedisMemoLock) InvalidateCache

func (r *RedisMemoLock) InvalidateCache(key string)

type RenewableFetchFunc

type RenewableFetchFunc = func(LockRenewFunc) (string, time.Duration, error)

RenewableFetchFunc has the same purpose as FetchFunc but, when called, it is offered a function that allows to extend the lock

Jump to

Keyboard shortcuts

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