Documentation ¶
Index ¶
- Constants
- Variables
- type CacheGetResponse
- type CacheKey
- type CacheKeyType
- type CacheServer
- type CacheStoreRequest
- type Client
- type ConnectTimeoutError
- type HashKey
- type HashKeyOrder
- type Hashring
- type Item
- type Iterator
- type MemcachedClient
- func (c *MemcachedClient) Add(key CacheKey, value []byte, expiration time.Duration) error
- func (c *MemcachedClient) CompareAndSwap(item *Item) error
- func (c *MemcachedClient) Decrement(key CacheKey, delta uint64) (newValue uint64, err error)
- func (c *MemcachedClient) Delete(key CacheKey) error
- func (c *MemcachedClient) DeleteAll() error
- func (c *MemcachedClient) Flush() error
- func (c *MemcachedClient) FlushAll() error
- func (c *MemcachedClient) Get(key CacheKey) (*CacheGetResponse, error)
- func (c *MemcachedClient) GetClient() *Client
- func (c *MemcachedClient) GetMulti(keys []CacheKey) (*Iterator, error)
- func (c *MemcachedClient) Increment(key CacheKey, delta uint64) (newValue uint64, err error)
- func (c *MemcachedClient) Replace(item *Item) error
- func (c *MemcachedClient) Set(req *CacheStoreRequest) error
- func (c *MemcachedClient) SetMaxIdleConnections(maxIdle int) error
- func (c *MemcachedClient) SetTimeout(timeout time.Duration) error
- func (c *MemcachedClient) Touch(key CacheKey, seconds int32) (err error)
- type RedisClient
- func (c *RedisClient) Add(key CacheKey, value []byte, expiration time.Duration) error
- func (c *RedisClient) Delete(key CacheKey) error
- func (c *RedisClient) Flush() error
- func (c *RedisClient) Get(key CacheKey) (*CacheGetResponse, error)
- func (c *RedisClient) GetClient() *Client
- func (c *RedisClient) GetMulti(keys []CacheKey) (*Iterator, error)
- func (c *RedisClient) Set(req *CacheStoreRequest) error
- func (c *RedisClient) SetMaxIdleConnections(maxIdle int) error
- func (c *RedisClient) SetTimeout(timeout time.Duration) error
- type Selector
- type StringCacheKey
Constants ¶
const ( StateKey int = iota StateFlag StateSize StateCasID )
Variables ¶
var ( ErrCacheMiss = xerrors.New("cache miss hit") // 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 = xerrors.New("malformed: key is too long or contains invalid characters") ErrSetTimeout = xerrors.New("timeout must be 1 or more") ErrSetMaxIdleConnections = xerrors.New("maxIdle must be 1 or more") )
var ( // ErrMemcacheCacheMiss means that a Get failed because the item wasn't present. ErrMemcacheCacheMiss = xerrors.New("memcache: cache miss") // ErrMemcacheCASConflict 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. ErrMemcacheCASConflict = xerrors.New("memcache: compare-and-swap conflict") // ErrMemcacheNotStored means that a conditional write operation (i.e. Add or // CompareAndSwap) failed because the condition was not satisfied. ErrMemcacheNotStored = xerrors.New("memcache: item not stored") // ErrMemcacheServerError means that a server error occurred. ErrMemcacheServerError = xerrors.New("memcache: server error") // ErrMemcacheNoStats means that no statistics were available. ErrMemcacheNoStats = xerrors.New("memcache: no statistics available") // ErrMemcacheNoServers is returned when no servers are configured or available. ErrMemcacheNoServers = xerrors.New("memcache: no servers configured or available") )
var ( ErrRedisCacheMiss = xerrors.New("redis: cache miss") ErrRedisNotStored = xerrors.New("redis: item not stored") )
var (
ErrCannotAssignCacheServer = xerrors.New("cannot assign cache server because server number is zero")
)
Functions ¶
This section is empty.
Types ¶
type CacheGetResponse ¶
type CacheKeyType ¶
type CacheKeyType int
const ( CacheKeyTypeNone CacheKeyType = iota CacheKeyTypeSLC CacheKeyTypeLLC )
func (CacheKeyType) MarshalJSON ¶
func (typ CacheKeyType) MarshalJSON() ([]byte, error)
func (CacheKeyType) String ¶
func (typ CacheKeyType) String() string
func (*CacheKeyType) UnmarshalJSON ¶
func (typ *CacheKeyType) UnmarshalJSON(bytes []byte) error
type CacheServer ¶
type CacheServer interface { GetClient() *Client Get(CacheKey) (*CacheGetResponse, error) GetMulti([]CacheKey) (*Iterator, error) Set(*CacheStoreRequest) error Add(CacheKey, []byte, time.Duration) error Delete(CacheKey) error Flush() error SetTimeout(time.Duration) error SetMaxIdleConnections(int) error }
func NewMemcachedBySelectors ¶
func NewMemcachedBySelectors(slcSelector *Selector, llcSelector *Selector) CacheServer
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 NewRedisBySelectors ¶
func NewRedisBySelectors(slcSelector *Selector, llcSelector *Selector) CacheServer
type CacheStoreRequest ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a memcache client. It is safe for unlocked use by multiple concurrent goroutines.
func (*Client) AddLastLevelCacheServers ¶
func (*Client) AddSecondLevelCacheServers ¶
func (*Client) RemoveLastLevelCacheServers ¶
func (*Client) RemoveSecondLevelCacheServers ¶
type ConnectTimeoutError ¶
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.
func (*ConnectTimeoutError) Error ¶
func (cte *ConnectTimeoutError) Error() string
type HashKeyOrder ¶
type HashKeyOrder []HashKey
func (HashKeyOrder) Len ¶
func (h HashKeyOrder) Len() int
func (HashKeyOrder) Less ¶
func (h HashKeyOrder) Less(i, j int) bool
func (HashKeyOrder) Swap ¶
func (h HashKeyOrder) Swap(i, j int)
type Hashring ¶
type Hashring struct {
// contains filtered or unexported fields
}
func NewHashring ¶
type Item ¶
type Item struct { // Key is the Item's key (250 bytes maximum). Key CacheKey // 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.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
func NewIterator ¶
func (*Iterator) Content ¶
func (i *Iterator) Content() *CacheGetResponse
func (*Iterator) SetContent ¶
func (i *Iterator) SetContent(idx int, res *CacheGetResponse)
type MemcachedClient ¶
type MemcachedClient struct {
// contains filtered or unexported fields
}
func (*MemcachedClient) CompareAndSwap ¶
func (c *MemcachedClient) CompareAndSwap(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.
func (*MemcachedClient) Decrement ¶
func (c *MemcachedClient) Decrement(key CacheKey, 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.
func (*MemcachedClient) Delete ¶
func (c *MemcachedClient) Delete(key CacheKey) error
func (*MemcachedClient) DeleteAll ¶
func (c *MemcachedClient) DeleteAll() error
DeleteAll deletes all items in the cache.
func (*MemcachedClient) Flush ¶
func (c *MemcachedClient) Flush() error
func (*MemcachedClient) FlushAll ¶
func (c *MemcachedClient) FlushAll() error
func (*MemcachedClient) Get ¶
func (c *MemcachedClient) Get(key CacheKey) (*CacheGetResponse, error)
func (*MemcachedClient) GetClient ¶
func (c *MemcachedClient) GetClient() *Client
func (*MemcachedClient) GetMulti ¶
func (c *MemcachedClient) GetMulti(keys []CacheKey) (*Iterator, error)
func (*MemcachedClient) Increment ¶
func (c *MemcachedClient) Increment(key CacheKey, delta uint64) (newValue uint64, err 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.
func (*MemcachedClient) Replace ¶
func (c *MemcachedClient) Replace(item *Item) error
Replace writes the given item, but only if the server *does* already hold data for this key
func (*MemcachedClient) Set ¶
func (c *MemcachedClient) Set(req *CacheStoreRequest) error
func (*MemcachedClient) SetMaxIdleConnections ¶
func (c *MemcachedClient) SetMaxIdleConnections(maxIdle int) error
func (*MemcachedClient) SetTimeout ¶
func (c *MemcachedClient) SetTimeout(timeout time.Duration) error
func (*MemcachedClient) Touch ¶
func (c *MemcachedClient) Touch(key CacheKey, seconds int32) (err 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.
type RedisClient ¶
type RedisClient struct {
// contains filtered or unexported fields
}
func (*RedisClient) Delete ¶
func (c *RedisClient) Delete(key CacheKey) error
func (*RedisClient) Flush ¶
func (c *RedisClient) Flush() error
func (*RedisClient) Get ¶
func (c *RedisClient) Get(key CacheKey) (*CacheGetResponse, error)
func (*RedisClient) GetClient ¶
func (c *RedisClient) GetClient() *Client
func (*RedisClient) Set ¶
func (c *RedisClient) Set(req *CacheStoreRequest) error
func (*RedisClient) SetMaxIdleConnections ¶
func (c *RedisClient) SetMaxIdleConnections(maxIdle int) error
func (*RedisClient) SetTimeout ¶
func (c *RedisClient) SetTimeout(timeout time.Duration) error
type Selector ¶
type Selector struct {
// contains filtered or unexported fields
}
func NewSelector ¶
type StringCacheKey ¶
type StringCacheKey string
func (StringCacheKey) Addr ¶
func (s StringCacheKey) Addr() net.Addr
func (StringCacheKey) Hash ¶
func (s StringCacheKey) Hash() uint32
func (StringCacheKey) LockKey ¶
func (s StringCacheKey) LockKey() CacheKey
func (StringCacheKey) String ¶
func (s StringCacheKey) String() string
func (StringCacheKey) Type ¶
func (s StringCacheKey) Type() CacheKeyType