memcache package - github.com/orijtech/gomemcache/memcache - Go Packages
Package memcache provides a client for the memcached cache server.
- Constants
- Variables
- type Client
- func (c *Client) Add(ctx context.Context, item *Item) error
- func (c *Client) CompareAndSwap(ctx context.Context, item *Item) error
- func (c *Client) Decrement(ctx context.Context, key string, delta uint64) (newValue uint64, err error)
- func (c *Client) Delete(ctx context.Context, key string) error
- func (c *Client) DeleteAll(ctx context.Context) error
- func (c *Client) FlushAll(ctx context.Context) error
- func (c *Client) Get(ctx context.Context, key string) (item *Item, err error)
- func (c *Client) GetMulti(ctx context.Context, keys []string) (m map[string]*Item, err error)
- func (c *Client) Increment(ctx context.Context, key string, delta uint64) (newValue uint64, err error)
- 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 ConnectTimeoutError
- type Item
- type ServerList
- type ServerSelector
var ( ErrCacheMiss = errors.New("memcache: cache miss") ErrCASConflict = errors.New("memcache: compare-and-swap conflict") ErrNotStored = errors.New("memcache: item not stored") ErrServerError = errors.New("memcache: server error") ErrNoStats = errors.New("memcache: no statistics available") ErrMalformedKey = errors.New("malformed: key is too long or contains invalid characters") ErrNoServers = errors.New("memcache: no servers configured or available") )
Metric Tags
var ( KeyLengthView = &view.View{ Name: "gomemcache/key_length", Description: "The distribution of the lengths of keys", Measure: mKeyLength, TagKeys: []tag.Key{KeyMethod}, Aggregation: view.Distribution(0, 20, 40, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260), } KeyValueLengthView = &view.View{ Name: "gomemcache/value_length", Description: "The distribution of the lengths of values", Measure: mValueLength, TagKeys: []tag.Key{KeyMethod}, Aggregation: view.Distribution( 0, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, 4611686018427387904, 9223372036854775808, ), } KeyCallsView = &view.View{ Name: "gomemcache/calls", Description: "Number of the various method invocations", Measure: mLatencyMs, TagKeys: []tag.Key{KeyMethod, KeyError, KeyStatus}, Aggregation: view.Count(), } KeyLatencyView = &view.View{ Name: "gomemcache/latency", Description: "The distribution of the latencies in milliseconds", Measure: mLatencyMs, TagKeys: []tag.Key{KeyMethod, KeyError, KeyStatus}, Aggregation: view.Distribution( 0.0, 0.000001, 0.000005, 0.00001, 0.00005, 0.0001, 0.0005, 0.001, 0.0015, 0.002, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.2, 0.4, 0.6, 0.8, 1.0, 1.5, 2.5, 5.0, 10.0, 20.0, 40.0, 100.0, 200.0, 500.0), } AllViews = []*view.View{ KeyLengthView, KeyValueLengthView, KeyCallsView, KeyLatencyView, } )
Metrics and views below:
This section is empty.
Client is a memcache client. It is safe for unlocked use by multiple concurrent goroutines.
New returns a memcache client using the provided server(s) with equal weight. If a server is listed multiple times, it gets a proportional amount of weight.
func NewFromSelector(ss ServerSelector) *Client
NewFromSelector returns a new Client using the provided ServerSelector.
Add writes the given item, if no value already exists for its key. ErrNotStored is returned if that condition is not met.
func (*Client) 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.
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.
Delete deletes the item with the provided key. The error ErrCacheMiss is returned if the item didn't already exist in the cache.
DeleteAll deletes all items in the cache.
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.
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.
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.
Replace writes the given item, but only if the server *does* already hold data for this key
Set writes the given item, unconditionally.
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.
ConnectTimeoutError is the error type used when it takes too long to connect to the desired host. This level of detail can generally be ignored.
Item is an item to be got or stored in a memcached server.
type ServerList struct {
}
ServerList is a simple ServerSelector. Its zero value is usable.
Each iterates over each server calling the given function
SetServers changes a ServerList's set of servers at runtime and is safe for concurrent use by multiple goroutines.
Each server is given equal weight. A server is given more weight if it's listed multiple times.
SetServers returns an error if any of the server names fail to resolve. No attempt is made to connect to the server. If any error is returned, no changes are made to the ServerList.
ServerSelector is the interface that selects a memcache server as a function of the item's key.
All ServerSelector implementations must be safe for concurrent use by multiple goroutines.