Documentation
¶
Overview ¶
Package memcache is a cache.Store on Memcached, in its own Go module so no client library reaches a project that does not import it.
Memcached is simpler than Redis, and the differences are real, so they are stated here instead of hidden behind a symmetric Config:
- No authentication. The client has no SASL, so Config has no username or password. Use network isolation, or TLS (below), as the security model.
- TLS only through the client's dialer, for a server started with --enable-ssl. Config.TLSConfig builds that dialer; nothing else is configurable.
- No in-flight cancellation. The client's calls take no context. The adapter checks the context before an operation begins, but once I/O has started Config.Timeout (default 500ms) is the bound.
- Several servers are sharded by key with no replication. Changing the server list remaps keys, which shows up as misses: acceptable for a cache, and why one cache must not hold anything you cannot recompute.
- Expiry has one-second granularity and zero means "never expires", so a TTL is rounded up to whole seconds and is never turned into zero.
A Store passes the cachetest conformance suite against a real server. See https://memcached.org for the server.
Index ¶
Constants ¶
const DefaultTimeout = 500 * time.Millisecond
DefaultTimeout is the socket read/write timeout used when Config.Timeout is zero.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Servers lists host:port addresses. It must not be empty. With more than
// one, keys are sharded across them with no replication.
Servers []string
// Timeout bounds each socket read and write, and so every operation once
// it has begun. Zero means DefaultTimeout; negative is invalid.
Timeout time.Duration
// MaxIdleConns is the most idle connections kept per server. Zero uses
// the client's default; negative is invalid.
MaxIdleConns int
// TLSConfig, when set, makes every connection use TLS (the server must be
// started with --enable-ssl). It is applied through the client's dialer.
TLSConfig *tls.Config
}
Config describes the Memcached servers a Store talks to.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a Memcached cache.Store. Close it when done.
func New ¶
New validates cfg and returns a Store. It does not connect: the client connects lazily and has no handshake to verify.