Documentation ¶
Index ¶
- Variables
- func Add(c context.Context, items ...Item) error
- func AddRawFilters(c context.Context, filts ...RawFilter) context.Context
- func CompareAndSwap(c context.Context, items ...Item) error
- func Delete(c context.Context, keys ...string) error
- func Flush(c context.Context) error
- func Get(c context.Context, items ...Item) error
- func Increment(c context.Context, key string, delta int64, initialValue uint64) (uint64, error)
- func IncrementExisting(c context.Context, key string, delta int64) (uint64, error)
- func Set(c context.Context, items ...Item) error
- func SetRaw(c context.Context, mc RawInterface) context.Context
- func SetRawFactory(c context.Context, mcf RawFactory) context.Context
- type Item
- type RawCB
- type RawFactory
- type RawFilter
- type RawInterface
- type RawItemCB
- type Statistics
Constants ¶
This section is empty.
Variables ¶
var ( ErrCacheMiss = orig.ErrCacheMiss ErrCASConflict = orig.ErrCASConflict ErrNoStats = orig.ErrNoStats ErrNotStored = orig.ErrNotStored ErrServerError = orig.ErrServerError )
These are pass-through versions from the managed-VM SDK. All implementations must return these (exact) errors (not just an error with the same text).
Functions ¶
func Add ¶
Add writes items to memcache iff they don't already exist.
If only one item is provided its error will be returned directly. If more than one item is provided, an errors.MultiError will be returned in the event of an error, with a given error index corresponding to the error encountered when processing the item at that index.
func AddRawFilters ¶
AddRawFilters adds RawInterface filters to the context.
func CompareAndSwap ¶
CompareAndSwap writes the given item that was previously returned by Get, if the value was neither modified or evicted between the Get and the CompareAndSwap calls.
Example:
itm := memcache.NewItem(context, "aKey") memcache.Get(context, itm) // check error itm.SetValue(append(itm.Value(), []byte("more bytes"))) memcache.CompareAndSwap(context, itm) // check error
If only one item is provided its error will be returned directly. If more than one item is provided, an errors.MultiError will be returned in the event of an error, with a given error index corresponding to the error encountered when processing the item at that index.
func Delete ¶
Delete deletes items from memcache.
If only one item is provided its error will be returned directly. If more than one item is provided, an errors.MultiError will be returned in the event of an error, with a given error index corresponding to the error encountered when processing the item at that index.
func Increment ¶
Increment adds delta to the uint64 contained at key. If the memcache key is missing, it's populated with initialValue before applying delta (i.e. the final value would be initialValue+delta).
Underflow caps at 0, overflow wraps back to 0.
The value is stored as little-endian uint64, see "encoding/binary".LittleEndian. If the value is not exactly 8 bytes, it's assumed to contain non-number data and this method will return an error.
func IncrementExisting ¶
IncrementExisting is like Increment, except that the value must exist already.
func Set ¶
Set writes items into memcache unconditionally.
If only one item is provided its error will be returned directly. If more than one item is provided, an errors.MultiError will be returned in the event of an error, with a given error index corresponding to the error encountered when processing the item at that index.
func SetRaw ¶
func SetRaw(c context.Context, mc RawInterface) context.Context
SetRaw sets the current RawInterface object in the context. Useful for testing with a quick mock. This is just a shorthand SetRawFactory invocation to SetRaw a RawFactory which always returns the same object.
func SetRawFactory ¶
func SetRawFactory(c context.Context, mcf RawFactory) context.Context
SetRawFactory sets the function to produce RawInterface instances, as returned by the Get method.
Types ¶
type Item ¶
type Item interface { Key() string Value() []byte Flags() uint32 Expiration() time.Duration SetKey(string) Item SetValue([]byte) Item SetFlags(uint32) Item SetExpiration(time.Duration) Item // SetAll copies all the values from other, except Key, into this item // (including the hidden CasID field). If other is nil, then all non-Key // fields are reset. SetAll(other Item) }
Item is a wrapper around *memcache.Item. Note that the Set* methods all return the original Item (e.g. they mutate the original), due to implementation constraints. They return the original item to allow easy chaining, e.g.:
itm := memcache.NewItem(c, "foo").SetValue([]byte("stuff"))
type RawCB ¶
type RawCB func(error)
RawCB is a simple error callback for most of the methods in RawInterface.
type RawFactory ¶
type RawFactory func(context.Context) RawInterface
RawFactory is the function signature for RawFactory methods compatible with SetRawFactory.
type RawFilter ¶
type RawFilter func(context.Context, RawInterface) RawInterface
RawFilter is the function signature for a RawFilter MC implementation. It gets the current MC implementation, and returns a new MC implementation backed by the one passed in.
type RawInterface ¶
type RawInterface interface { NewItem(key string) Item AddMulti(items []Item, cb RawCB) error SetMulti(items []Item, cb RawCB) error GetMulti(keys []string, cb RawItemCB) error DeleteMulti(keys []string, cb RawCB) error CompareAndSwapMulti(items []Item, cb RawCB) error Increment(key string, delta int64, initialValue *uint64) (newValue uint64, err error) Flush() error Stats() (*Statistics, error) }
RawInterface is the full interface to the memcache service.
func Raw ¶
func Raw(c context.Context) RawInterface
Raw gets the current memcache implementation from the context.
type RawItemCB ¶
RawItemCB is the callback for RawInterface.GetMulti. It takes the retrieved item and the error for that item (e.g. ErrCacheMiss) if there was one. Item is guaranteed to be nil if error is not nil.
type Statistics ¶
type Statistics struct { Hits uint64 // Counter of cache hits Misses uint64 // Counter of cache misses ByteHits uint64 // Counter of bytes transferred for gets Items uint64 // Items currently in the cache Bytes uint64 // Size of all items currently in the cache Oldest int64 // Age of access of the oldest item, in seconds }
Statistics represents a set of statistics about the memcache cache. This may include items that have expired but have not yet been removed from the cache.