gae: go.chromium.org/gae/service/memcache Index | Files

package memcache

import "go.chromium.org/gae/service/memcache"

Index

Package Files

context.go errors.go interface.go raw_interface.go types.go

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).

func Add Uses

func Add(c context.Context, items ...Item) error

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 Uses

func AddRawFilters(c context.Context, filts ...RawFilter) context.Context

AddRawFilters adds RawInterface filters to the context.

func CompareAndSwap Uses

func CompareAndSwap(c context.Context, items ...Item) error

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 Uses

func Delete(c context.Context, keys ...string) error

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 Flush Uses

func Flush(c context.Context) error

Flush dumps the entire memcache state.

func Get Uses

func Get(c context.Context, items ...Item) error

Get retrieves items from memcache.

func Increment Uses

func Increment(c context.Context, key string, delta int64, initialValue uint64) (uint64, error)

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 Uses

func IncrementExisting(c context.Context, key string, delta int64) (uint64, error)

IncrementExisting is like Increment, except that the value must exist already.

func Set Uses

func Set(c context.Context, items ...Item) error

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 Uses

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 Uses

func SetRawFactory(c context.Context, mcf RawFactory) context.Context

SetRawFactory sets the function to produce RawInterface instances, as returned by the Get method.

type Item Uses

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"))

func GetKey Uses

func GetKey(c context.Context, key string) (Item, error)

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.

func NewItem Uses

func NewItem(c context.Context, key string) Item

NewItem creates a new, mutable, memcache item.

type RawCB Uses

type RawCB func(error)

RawCB is a simple error callback for most of the methods in RawInterface.

type RawFactory Uses

type RawFactory func(context.Context) RawInterface

RawFactory is the function signature for RawFactory methods compatible with SetRawFactory.

type RawFilter Uses

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 Uses

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 Uses

func Raw(c context.Context) RawInterface

Raw gets the current memcache implementation from the context.

type RawItemCB Uses

type RawItemCB func(Item, error)

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 Uses

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 Uses

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 42 packages. Updated 2018-08-15. Refresh now. Tools for package owners.