Documentation ¶
Overview ¶
Package memcached provides a client for the memcached cache server.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( DefaultTimeout = time.Duration(time.Second * 3) DefaultMaxIdleConns = 100 )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // FlushAll deletes all items in the cache. FlushAll() error // 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. Get(key string) (*item.Item, error) // 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. Zero means the item has // no expiration time. ErrCacheMiss is returned if the key is not in the cache. // The key must be at most 250 bytes in length. Touch(key string, seconds int32) (err error) // 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. GetMulti(keys []string) (map[string]*item.Item, error) // Set writes the given item, unconditionally. Set(item *item.Item) error // Add writes the given item, if no value already exists for its // key. ErrNotStored is returned if that condition is not met. Add(item *item.Item) error // Replace writes the given item, but only if the server *does* // already hold data for this key. Replace(item *item.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. 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. CompareAndSwap(item *item.Item) error // Delete deletes the item with the provided key. The error ErrCacheMiss is // returned if the item didn't already exist in the cache. Delete(key string) error // DeleteAll deletes all items in the cache. DeleteAll() error // Ping checks all instances if they are alive. Returns error if any // of them is down. Ping() error // 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. Increment(key string, delta uint64) (newValue uint64, err error) // 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. Decrement(key string, delta uint64) (newValue uint64, err error) // Exists returns true if an item with the given key exists. Exists(key string) (bool, error) }
type ClientBuilder ¶
type ClientBuilder interface { // SetTimeout specifies the socket read/write timeout. // If zero, DefaultTimeout is used. SetTimeout(timeout time.Duration) ClientBuilder // MaxIdleConns specifies the maximum number of idle connections that will // be maintained per address. If less than one, DefaultMaxIdleConns will be // used. // // Consider your expected traffic rates and latency carefully. This should // be set to a number higher than your peak parallel requests. SetMaxIdleConns(i int) ClientBuilder // WithServers configures the client to use the provided server(s) // with equal weight. If a server is listed multiple times, // it gets a proportional amount of weight. WithServers(servers ...string) ClientBuilder // Build builds the memcache client. Build() Client }
ClientBuilder is the interface for building a client.
Click to show internal directories.
Click to hide internal directories.