import "go.chromium.org/luci/gae/service/memcache"
context.go errors.go interface.go raw_interface.go types.go
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).
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.
AddRawFilters adds RawInterface filters to the context.
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.
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.
Flush dumps the entire memcache state.
Get retrieves items from memcache.
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.
IncrementExisting is like Increment, except that the value must exist already.
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.
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.
SetRawFactory sets the function to produce RawInterface instances, as returned by the Get method.
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"))
GetKey is a convenience method for generating and retrieving an Item instance for the specified from memcache key.
On a cache miss ErrCacheMiss will be returned. Item will always be returned, even on a miss, but it's value may be empty if it was a miss.
NewItem creates a new, mutable, memcache item.
RawCB is a simple error callback for most of the methods in RawInterface.
type RawFactory func(context.Context) RawInterface
RawFactory is the function signature for RawFactory methods compatible with SetRawFactory.
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 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(c context.Context) RawInterface
Raw gets the current memcache implementation from the context.
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 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.
func Stats(c context.Context) (*Statistics, error)
Stats gets some best-effort statistics about the current state of memcache.
Package memcache imports 4 packages (graph) and is imported by 29 packages. Updated 2021-01-26. Refresh now. Tools for package owners.