cache

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(ctx context.Context, key string) error

Delete key from cache

func DeleteMulti

func DeleteMulti(ctx context.Context, keys []string) error

func Increment

func Increment(ctx context.Context, key string, delta int64, initialValue uint64) (newValue uint64, err error)

func IncrementExisting

func IncrementExisting(ctx context.Context, key string, delta int64) (newValue uint64, err error)

func IncrementOrSet

func IncrementOrSet(ctx context.Context, key string, delta int64, iv func(ctx context.Context) (uint64, time.Duration, error), options ...CacheOptions) (uint64, error)

IncrementOrSet works like Increment but assumes that the key already exists in memcache. If the key doesn't exist in memcache, iv is used to set the initial value and delta is not applied. The value in the cache (after delta or set) is returned.

func Remember

func Remember(ctx context.Context, key string, expiration time.Duration, p SlowRetrieve, options ...CacheOptions) (interface{}, error)

Remember is used to retrieve values from the cache, and if it doesn't exist, then retrieve them using p

func Retrieve

func Retrieve(ctx context.Context, key string, options ...CacheOptions) (string, error)

Retrieve val in cache without any Gob encoding

func RetrieveGob

func RetrieveGob(ctx context.Context, key string, options ...CacheOptions) (interface{}, error)

RetrieveGob will retrieve the value from the cache. Type assertion will need to be performed in order to use the value

func Store

func Store(ctx context.Context, key string, expiration time.Duration, val interface{}, options ...CacheOptions) error

Store val in cache without any Gob encoding.

func StoreGob

func StoreGob(ctx context.Context, key string, expiration time.Duration, val interface{}, options ...CacheOptions) error

StoreGob will store val in the cache after encoding it as a Gob.

Types

type CacheOptions

type CacheOptions struct {
	// DisableCacheUsage disables the cache. (Usually for debugging)
	DisableCacheUsage bool
	// UseFreshData will ignore content in the cache and pull fresh data.
	// The pulled data will subsequently be saved in the cache
	UseFreshData bool
	//Turn on logging
	Log bool
}

type Key

type Key string

func CreateKey

func CreateKey(prefix bool, sep string, visual string, args ...interface{}) Key

CreateKey will generate a key based on the input arguments. When prefix is true, the caller's name will be used to prefix the key in an attempt to make it unique. The args can also be separated using sep. visual does not do anything. It is used at code level to easily see how the key should look

func (Key) Hash

func (k Key) Hash() Key

Hash returns a crc32 version of key

func (Key) String

func (k Key) String() string

String returns a string version of the key

type SlowRetrieve

type SlowRetrieve func(ctx context.Context) (interface{}, error)

Jump to

Keyboard shortcuts

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