cachelock

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLockExpiration = time.Minute * 5

Variables

View Source
var (
	ErrNotAcquired = errors.New("lock not acquired")
	ErrNotReleased = errors.New("lock not released")
)
View Source
var (
	NoRetryStrategy = LinearBackoffStrategy(0)
)

Functions

This section is empty.

Types

type Lock

type Lock interface {
	Release(context.Context) error
}

Lock is a handle on an acquired lock.

type Locker

type Locker interface {
	Acquire(ctx context.Context, key string) (Lock, error)
}

Locker is a service that provides a lock for a resource.

func New

func New(client cache.Client, expiration time.Duration, retryStrategy RetryStrategy) Locker

type MockLock

type MockLock struct {
	mock.Mock
}

func ExpectAcquireAndRelease

func ExpectAcquireAndRelease(locker *MockLocker, key string) *MockLock

func NewMockLock

func NewMockLock() *MockLock

func (*MockLock) Release

func (m *MockLock) Release(ctx context.Context) error

type MockLocker

type MockLocker struct {
	mock.Mock
}

func NewMockLocker

func NewMockLocker() *MockLocker

func (*MockLocker) Acquire

func (m *MockLocker) Acquire(ctx context.Context, key string) (Lock, error)

type RetryAttempt

type RetryAttempt interface {
	// NextBackoff returns the next backoff duration.
	NextBackoff() time.Duration
}

RetryAttempt allows to customise the lock retry strategy.

func ExponentialBackoff

func ExponentialBackoff(min, max time.Duration) RetryAttempt

ExponentialBackoff strategy is an optimization strategy with a retry time of 2**n milliseconds (n means number of times). You can set a minimum and maximum value, the recommended minimum value is not less than 16ms.

func LinearBackoff

func LinearBackoff(backoff time.Duration) RetryAttempt

LinearBackoff allows retries regularly with customized intervals

func NoRetry

func NoRetry() RetryAttempt

NoRetry acquire the lock only once.

type RetryStrategy

type RetryStrategy func() RetryAttempt

func AttemptBoundRetryStrategy added in v2.3.0

func AttemptBoundRetryStrategy(maxAttempts int, retryStrategy RetryStrategy) RetryStrategy

func ExponentialBackoffStrategy

func ExponentialBackoffStrategy(min, max time.Duration) RetryStrategy

func LinearBackoffStrategy

func LinearBackoffStrategy(backoff time.Duration) RetryStrategy

Jump to

Keyboard shortcuts

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