cache

package
v0.0.0-...-2e7882b Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2017 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Overview

Package cache defines common interfaces and error types which are implemented by drivers

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCacheMiss is returned when the key isn't in the cache
	ErrCacheMiss = errors.New("cache miss")
	// ErrInvalidDstVal is returned with the dstVal of the Get() func cannot be set. It's probably because the
	// dstVal is not a pointer.
	ErrInvalidDstVal = errors.New("cannot set dst value")
	// ErrInvalidDataFormat is returned when the data retrieved from a storage engine is not in the expected format
	ErrInvalidDataFormat = errors.New("Invalid data format")
	// ErrKeyExists indicates that the item you are trying to store with
	// a "cas" command has been modified since you last fetched it.
	ErrKeyExists = errors.New("key already exists")
	// ErrNotStored indicate the data was not stored, but not
	// because of an error. This normally means that the
	// condition for an "add" or a "replace" command wasn't met.
	ErrNotStored = errors.New("not stored")
	// ErrNotFound indicates that the item you are trying to store
	// with a "cas" command did not exist.
	ErrNotFound = errors.New("not found")
	// ErrUnsupportedAction indicates that the selected driver doesn't support the given action
	ErrUnsupportedAction = errors.New("not supported")
	// ErrCannotSetValue is returned when an previously set cache value pointer cannot be set.
	ErrCannotSetValue = errors.New("cannot set value of interface")
	// ErrCannotAssignValue is returned when a previously set cache value pointer cannot be
	// updated because the new value's type cannot be assigned to the previous value's type.
	ErrCannotAssignValue = errors.New("cannot assign value")
	// ErrCASConflict means that a CompareAndSwap call failed due to the
	// cached value being modified between the Get and the CompareAndSwap.
	// If the cached value was simply evicted rather than replaced,
	// ErrNotStored will be returned instead.
	ErrCASConflict = errors.New("compare-and-swap conflict")
	// NeverExpires is the duration which should be set for a key to never expire because of duration
	NeverExpires = time.Duration(0)
)

Functions

func Copy

func Copy(srcVal interface{}, dstVal interface{}) error

Copy copies one interface into the other doing type checking to make sure it's safe. If it cannot be copied, an error is returned.

func Key

func Key(key interface{}) string

Key turns Stringer funcs, byte slices, pointers to strings, etc., into string keys

Types

type Add

type Add interface {
	Add(key string, value interface{}, exp time.Duration) error
}

Add defines an interface which adds the key/value to the cache but only if the key doesn't already exist in the cache. If it does exist, it must return an ErrNotStored error

type Append

type Append interface {
	Append(key string, value interface{}) error
}

Append defines an interface which appends the value to the current value for the key. If the key doesn't already exist, it must return a ErrCacheMiss error

type Cache

type Cache interface {
	Set(key string, value interface{}, expiration time.Duration) error
	Get(key string, dstVal interface{}) error
	Exists(key string) bool
	Del(key string) error
}

Cache defines a cache with key expiration. Implementations of this interface are expected to be thread safe.

type Cachestore

type Cachestore interface {
	Cache
	KeyList
	Transfer(Cache) error
}

Cachestore defines a cache interface which supports exporting all it's keys and also transferring all it's data to another Cache.

type Decrement

type Decrement interface {
	Decrement(key string, delta uint64) (uint64, error)
}

Decrement defines an interface for caches which can decrement a key's value

type Flush

type Flush interface {
	Flush() error
}

Flush defines an interface which store can clear all it's key/value pairs at once.

type Increment

type Increment interface {
	Increment(key string, delta uint64) (uint64, error)
}

Increment defines an interface for caches which can increment a key's value

type KeyList

type KeyList interface {
	Keys() []string
}

KeyList defines an interface for announcing all keys currently set

type KeyProvider

type KeyProvider interface {
	Key() string
}

KeyProvider is an interface which can describe it's own key. It's used for getting/setting key/value pairs without a directly supplied key string. Instead, the supplied interface can announce it's own key, and that's used in getting/setting.

type Prepend

type Prepend interface {
	Prepend(key string, value interface{}) error
}

Prepend defines an interface which prepends the value to the current value for the key. If the key doesn't already exist, it must return a ErrCacheMiss error

type Replace

type Replace interface {
	Replace(key string, value interface{}) error
}

Replace defines an interface which replaces the value to the current value for the key. If the key doesn't already exist, it must return a ErrNotStored error

type Store

type Store interface {
	Set(key string, value interface{}) error
	Get(key string, dstVal interface{}) error
	Del(key string) error
}

Store defines a permanent key/value store. The storage mechanism should be permanent, not volitile.

type Touch

type Touch interface {
	Touch(key string, exp time.Duration) error
}

Touch defines an interface for caches which can touch item's expiration time.

Jump to

Keyboard shortcuts

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