Skip to main content

Module memcached

Module memcached 

Source
Expand description

Memcached backend via the rust-memcache client. Memcached backend via rust-memcache (r2d2-pooled, per-socket read/write timeouts, ASCII protocol).

§Why the ASCII protocol

The connection URL pins protocol=ascii (the same protocol cachekit-py’s pymemcache speaks) deliberately: rust-memcache’s binary-protocol parser does not correlate responses to requests (opcode/opaque unchecked), so a connection desynced by a timed-out operation could serve a late response as the answer to the next command — worst case a wrong value for a different key. The ASCII get validates the echoed key, and a desynced connection fails its next pool-checkout ping and is discarded. Every operation additionally runs under a hard async time budget (see crate::backend::memcached::MemcachedBackendBuilder::timeout) so a wedged server surfaces as a Timeout error instead of hanging callers.

§TTL capability — the honest parity picture

cachekit-py’s Memcached backend implements refresh_ttl (wrapping the memcached touch command) but not get_ttl — the classic memcached protocol has no command to read a key’s remaining TTL. That makes py’s Memcached not a TTLInspectableBackend; its refresh_ttl is a bare, directly-callable method outside the protocol.

This backend mirrors that exactly: no TtlInspectable impl (the trait requires the unreadable ttl()), and a bare inherent refresh_ttl wrapping touch. Rust could read TTLs via the meta protocol (mg <key> t, memcached >= 1.6), but shipping a capability py cannot match would make TTL-driven behaviour diverge between SDKs on the same cluster. Revisit only when cachekit-py gains meta-protocol support.

§Why rust-memcache

The previously used async-memcached 0.6 ships toxiproxy_rust (a fault injection test proxy) as a non-optional runtime dependency, dragging openssl/native-tls/hyper-0.14 into a rustls-only SDK — so it was rejected. rust-memcache with default-features = false has a lean tree, a connection pool (one hung connection doesn’t wedge the backend), per-socket timeouts, and touch.

Structs§

MemcachedBackend
Memcached backend powered by rust-memcache.
MemcachedBackendBuilder
Builder for MemcachedBackend.