Version: v3.0.0+incompatible Latest Latest

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

Go to latest
Published: Oct 24, 2017 License: MIT Imports: 2 Imported by: 7




This section is empty.


View Source
var (
	ErrNonExistentKey   = errors.New("non-existent key")
	ErrKeyAlreadyLocked = errors.New("key already locked")
	ErrInvalidData      = errors.New("invalid data")
	ErrEngineLocked     = errors.New("data is being regenerated by another process")



This section is empty.


type Engine

type Engine interface {
	Exists(string) bool
	Get(string) ([]byte, error)
	Put(string, []byte, time.Time) error

	Expire(string) error
	IsExpired(string) bool

	Lock(string) error
	Unlock(string) error
	IsLocked(string) bool

Engine is the interface all caching engines must adhere to

type EngineMock added in v1.0.1

type EngineMock struct {
	// ExistsFunc mocks the Exists function.
	ExistsFunc func(in1 string) bool
	// ExpireFunc mocks the Expire function.
	ExpireFunc func(in1 string) error
	// GetFunc mocks the Get function.
	GetFunc func(in1 string) ([]byte, error)
	// IsExpiredFunc mocks the IsExpired function.
	IsExpiredFunc func(in1 string) bool
	// IsLockedFunc mocks the IsLocked function.
	IsLockedFunc func(in1 string) bool
	// LockFunc mocks the Lock function.
	LockFunc func(in1 string) error
	// PutFunc mocks the Put function.
	PutFunc func(in1 string, in2 []byte, in3 time.Time) error
	// UnlockFunc mocks the Unlock function.
	UnlockFunc func(in1 string) error

EngineMock is a mock implementation of Engine.

    func TestSomethingThatUsesEngine(t *testing.T) {

        // make and configure a mocked Engine
        mockedEngine := &EngineMock{
            ExistsFunc: func(in1 string) bool {
	               panic("TODO: mock out the Exists function")
            ExpireFunc: func(in1 string) error {
	               panic("TODO: mock out the Expire function")
            GetFunc: func(in1 string) ([]byte, error) {
	               panic("TODO: mock out the Get function")
            IsExpiredFunc: func(in1 string) bool {
	               panic("TODO: mock out the IsExpired function")
            IsLockedFunc: func(in1 string) bool {
	               panic("TODO: mock out the IsLocked function")
            LockFunc: func(in1 string) error {
	               panic("TODO: mock out the Lock function")
            PutFunc: func(in1 string, in2 []byte, in3 time.Time) error {
	               panic("TODO: mock out the Put function")
            UnlockFunc: func(in1 string) error {
	               panic("TODO: mock out the Unlock function")

        // TODO: use mockedEngine in code that requires Engine


func (*EngineMock) Exists added in v1.0.1

func (mock *EngineMock) Exists(in1 string) bool

Exists calls ExistsFunc.

func (*EngineMock) Expire added in v1.0.1

func (mock *EngineMock) Expire(in1 string) error

Expire calls ExpireFunc.

func (*EngineMock) Get added in v1.0.1

func (mock *EngineMock) Get(in1 string) ([]byte, error)

Get calls GetFunc.

func (*EngineMock) IsExpired added in v1.0.1

func (mock *EngineMock) IsExpired(in1 string) bool

IsExpired calls IsExpiredFunc.

func (*EngineMock) IsLocked added in v1.0.1

func (mock *EngineMock) IsLocked(in1 string) bool

IsLocked calls IsLockedFunc.

func (*EngineMock) Lock added in v1.0.1

func (mock *EngineMock) Lock(in1 string) error

Lock calls LockFunc.

func (*EngineMock) Put added in v1.0.1

func (mock *EngineMock) Put(in1 string, in2 []byte, in3 time.Time) error

Put calls PutFunc.

func (*EngineMock) Unlock added in v1.0.1

func (mock *EngineMock) Unlock(in1 string) error

Unlock calls UnlockFunc.

Jump to

Keyboard shortcuts

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