Documentation ¶
Index ¶
- Variables
- func InitLocalCache(cfg *ristretto.Config)
- type ExternalFetchFunc
- type FetchFunc
- type LockRenewFunc
- type MemoLockConfig
- type RedisMemoLock
- func (r *RedisMemoLock) Close()
- func (r *RedisMemoLock) GetResource(ctx context.Context, resID string, timeout time.Duration, ...) (string, error)
- func (r *RedisMemoLock) GetResourceExternal(ctx context.Context, resID string, timeout time.Duration, ...) (string, error)
- func (r *RedisMemoLock) GetResourceRenewable(ctx context.Context, resID string, timeout time.Duration, ...) (string, error)
- func (r *RedisMemoLock) InvalidateCache(key string)
- type RenewableFetchFunc
Constants ¶
This section is empty.
Variables ¶
var ErrCacheNotFound = errors.New("Key not found")
ErrCacheNotFound happens when cache with certain key not exist
var ErrClosing = errors.New("Operation canceled by Close()")
ErrClosing happens when calling Close(), all pending requests will be failed with this error
var ErrLockRenew = errors.New("Unable to renew the lock")
ErrLockRenew happens when trying to renew a lock that expired already
var ErrTimeOut = errors.New("Operation Timed Out")
ErrTimeOut happens when the given timeout expires
Functions ¶
func InitLocalCache ¶
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 ¶
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 ¶
LockRenewFunc is the function that RenewableFetchFunc will get as input and that must be called to extend a locks' life
type MemoLockConfig ¶
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 (*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