Documentation ¶
Overview ¶
Package memcache provides a client for the memcached cache server.
Index ¶
- Variables
- func IsResumableErr(err error) bool
- type Client
- func (c *Client) Add(ctx context.Context, item *Item) error
- func (c *Client) Close()
- func (c *Client) CompareAndSwap(ctx context.Context, item *Item) error
- func (c *Client) Decrement(ctx context.Context, key string, delta uint64) (d uint64, err error)
- func (c *Client) Delete(ctx context.Context, key string) error
- func (c *Client) Get(ctx context.Context, key string) (i *Item, err error)
- func (c *Client) GetMulti(ctx context.Context, keys []string) (is map[string]*Item, err error)
- func (c *Client) Increment(ctx context.Context, key string, delta uint64) (d uint64, err error)
- func (c *Client) PoolStats() *pool.Stats
- func (c *Client) Replace(ctx context.Context, item *Item) error
- func (c *Client) Set(ctx context.Context, item *Item) error
- func (c *Client) Touch(ctx context.Context, key string, seconds int32) error
- type Conn
- func (c *Conn) Add(item *Item) error
- func (c *Conn) CompareAndSwap(item *Item) error
- func (c *Conn) Decrement(key string, delta uint64) (newValue uint64, err error)
- func (c *Conn) Delete(key string) error
- func (c *Conn) FlushAll() error
- func (c *Conn) Get(key string) (*Item, error)
- func (c *Conn) GetMulti(keys []string) (map[string]*Item, error)
- func (c *Conn) Increment(key string, delta uint64) (newValue uint64, err error)
- func (c *Conn) Replace(item *Item) error
- func (c *Conn) Set(item *Item) error
- func (c *Conn) Touch(key string, seconds int32) (err error)
- type Item
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCacheMiss means that a Get failed because the item wasn't present. ErrCacheMiss = errors.New("memcache: cache miss") // ErrCASConflict means that a CompareAndSwap call failed due to the // cached value being modified between the Get and the CompareAndSwap. // If the cached value was simply evicted rather than replaced, // ErrNotStored will be returned instead. ErrCASConflict = errors.New("memcache: compare-and-swap conflict") // ErrNotStored means that a conditional write operation (i.e. Add or // CompareAndSwap) failed because the condition was not satisfied. ErrNotStored = errors.New("memcache: item not stored") // ErrMalformedKey is returned when an invalid key is used. // Keys must be at maximum 250 bytes long and not // contain whitespace or control characters. ErrMalformedKey = errors.New("malformed: key is too long or contains invalid characters") )
Functions ¶
func IsResumableErr ¶
IsResumableErr returns true if err is only a protocol-level cache error. This is used to determine whether or not a server connection should be re-used or not. If an error occurs, by default we don't reuse the connection, unless it was just a cache error.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client memcache client
func (*Client) CompareAndSwap ¶
CompareAndSwap cas set
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a memcache client. It is safe for unlocked use by multiple concurrent goroutines.
func (*Conn) Add ¶
Add writes the given item, if no value already exists for its key. ErrNotStored is returned if that condition is not met.
func (*Conn) 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. The item's Key should not change between calls but all other item fields may differ. ErrCASConflict is returned if the value was modified in between the calls. ErrNotStored is returned if the value was evicted in between the calls.
func (*Conn) Decrement ¶
Decrement atomically decrements key by delta. The return value is the new value after being decremented or an error. If the value didn't exist in memcached the error is ErrCacheMiss. The value in memcached must be an decimal number, or an error will be returned. On underflow, the new value is capped at zero and does not wrap around.
func (*Conn) Delete ¶
Delete deletes the item with the provided key. The error ErrCacheMiss is returned if the item didn't already exist in the cache.
func (*Conn) Get ¶
Get gets the item for the given key. ErrCacheMiss is returned for a memcache cache miss. The key must be at most 250 bytes in length.
func (*Conn) GetMulti ¶
GetMulti is a batch version of Get. The returned map from keys to items may have fewer elements than the input slice, due to memcache cache misses. Each key must be at most 250 bytes in length. If no error is returned, the returned map will also be non-nil.
func (*Conn) Increment ¶
Increment atomically increments key by delta. The return value is the new value after being incremented or an error. If the value didn't exist in memcached the error is ErrCacheMiss. The value in memcached must be an decimal number, or an error will be returned. On 64-bit overflow, the new value wraps around.
func (*Conn) Replace ¶
Replace writes the given item, but only if the server *does* already hold data for this key
func (*Conn) Touch ¶
Touch updates the expiry for the given key. The seconds parameter is either a Unix timestamp or, if seconds is less than 1 month, the number of seconds into the future at which time the item will expire. ErrCacheMiss is returned if the key is not in the cache. The key must be at most 250 bytes in length.
type Item ¶
type Item struct { // Key is the Item's key (250 bytes maximum). Key string // Value is the Item's value. Value []byte // Flags are server-opaque flags whose semantics are entirely // up to the app. Flags uint32 // Expiration is the cache expiration time, in seconds: either a relative // time from now (up to 1 month), or an absolute Unix epoch time. // Zero means the Item has no expiration time. Expiration int32 // contains filtered or unexported fields }
Item is an item to be got or stored in a memcached server.