memcache

package
v0.0.0-...-f39a356 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: GPL-2.0, GPL-2.0 Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Codec = memcache.Gob
View Source
var ErrCacheMiss = memcache.ErrCacheMiss
View Source
var MemcacheEnabled = true

Functions

func CAS

func CAS(c TransactionContext, key string, expected, replacement interface{}) (success bool, err error)

CAS will replace expected with replacement in memcache if expected is the current value.

func Del

func Del(c TransactionContext, keys ...string) (err error)

Del will delete the keys from memcache.

If c is InTransaction it will put the actual deletion inside c.AfterTransaction, otherwise the deletion will execute immediately.

func Get

func Get(c TransactionContext, key string, val interface{}) (found bool, err error)

Get will lookup key and load it into val.

If c is in a transaction no lookup will take place.

func Incr

func Incr(c TransactionContext, key string, delta int64, initial uint64) (newValue uint64, err error)

func IncrExisting

func IncrExisting(c TransactionContext, key string, delta int64) (newValue uint64, err error)

func Keyify

func Keyify(k string) (result string, err error)

Keyify will create a memcache-safe key from k by hashing and base64-encoding it.

func Memoize

func Memoize(c TransactionContext, key string, destP interface{}, f func() (interface{}, error)) (err error)

Memoize will lookup key and load it into destinatinoPointer. A missing value will be generated by the generatorFunction and saved in memcache.

func Memoize2

func Memoize2(c TransactionContext, super, key string, destP interface{}, f func() (interface{}, error)) (err error)

Memoize will lookup super and generate a new key from its contents and key. If super is missing a new random value will be inserted there.

It will then lookup that key and load it into destinatinoPointer. A missing value will be generated by the generatorFunction and saved in memcache.

It returns whether the value was nil (either from memcache or from the generatorFunction).

Deleting super will invalidate all keys under it due to the composite keys being impossible to regenerate again.

func MemoizeDuring

func MemoizeDuring(c TransactionContext, key string, duration time.Duration, cacheNil bool, destP interface{}, f func() (interface{}, error)) (err error)

MemoizeDuring will lookup key and load it into destinatinoPointer. A missing value will be generated by the generatorFunction and saved in memcache with a timeout of duration.

func MemoizeDuringSmart

func MemoizeDuringSmart(c TransactionContext, key string, cacheNil bool, destP interface{}, f func() (interface{}, time.Duration, error)) (err error)

MemoizeDuringSmart will lookup key and load it into destinatinoPointer. A missing value will be generated by the generatorFunction and saved in memcache with a timeout of duration.

func MemoizeMulti

func MemoizeMulti(c TransactionContext, keys []string, destinationPointers []interface{}, generatorFunctions []func() (interface{}, error)) (errors appengine.MultiError)

MemoizeMulti will look for all provided keys, and load them into the destinationPointers.

Any missing values will be generated using the generatorFunctions and put in memcache without a timeout.

func Put

func Put(c TransactionContext, key string, val interface{}) (err error)

Put will put val under key.

func PutUntil

func PutUntil(c TransactionContext, until time.Duration, key string, val interface{}) (err error)

PutUntil will put val under key for at most until.

Types

type TransactionContext

type TransactionContext interface {
	context.Context
	InTransaction() bool
	AfterTransaction(interface{}) error
}

Jump to

Keyboard shortcuts

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