Skip to main content

varco-memcached

PyPI version Memcached cache backend for the varco framework.

MemcachedCache implements varco_core.cache.CacheBackend on top of aiomcache. Values are serialized (JSON by default) and stored in Memcached; TTL is enforced natively via Memcached's exptime.


Installation

uv add varco-memcached
# or: pip install varco-memcached

Requires a running Memcached server (memcached -p 11211).


Quick start

from varco_memcached import MemcachedCache, MemcachedCacheSettings

settings = MemcachedCacheSettings(host="localhost", port=11211, key_prefix="myapp:")

cache = MemcachedCache(settings)
await cache.start()

await cache.set("user:42", {"name": "Ada"}, ttl=300)
value = await cache.get("user:42")  # {"name": "Ada"}

await cache.stop()

Configuration

MemcachedCacheSettings reads from environment variables under the VARCO_MEMCACHED_CACHE_ prefix (kept separate from any Redis settings in the same process):

Field Default Env var
host "localhost" VARCO_MEMCACHED_CACHE_HOST
port 11211 VARCO_MEMCACHED_CACHE_PORT
pool_size 2 VARCO_MEMCACHED_CACHE_POOL_SIZE
key_prefix "" VARCO_MEMCACHED_CACHE_KEY_PREFIX
settings = MemcachedCacheSettings.from_env()

Key differences from varco_redis.RedisCache

  • Keys must be bytesaiomcache requires byte keys; varco_memcached encodes the prefixed key as UTF-8 internally.
  • No native key enumeration. Memcached has no SCAN-equivalent command. clear() only removes keys written by this MemcachedCache instance in the current process (tracked in an in-process registry) — keys written by other processes, or surviving a restart, are unaffected and expire via TTL. Use the server's flush_all() for a full flush (affects every client sharing that server).
  • No native exists(). It performs a get and checks for None — a full round trip, though deserialization is skipped.
  • TTL semantics differ. Memcached's exptime of 0 means "never expire" — the opposite convention from a bare Redis SET with no TTL.
  • Key length limit. Memcached rejects keys over 250 bytes or containing whitespace/control characters — MemcachedCacheSettings.memcached_key() does not validate this; callers are responsible for keeping keys short.

DI integration

Unlike scan-only event bus backends, MemcachedCache needs an async start() call to open its connection pool — wiring goes through MemcachedCacheConfiguration, a providify @Configuration:

from providify import DIContainer
from varco_core.cache import CacheBackend
from varco_memcached.di import async_bootstrap

container = await async_bootstrap()  # installs MemcachedCacheConfiguration
cache = await container.aget(CacheBackend)  # started MemcachedCache singleton
await cache.set("key", "value", ttl=60)
await container.ashutdown()  # stops the cache via @PreDestroy

Or manually:

from providify import DIContainer
from varco_memcached.cache import MemcachedCacheConfiguration

container = DIContainer()
await container.ainstall(MemcachedCacheConfiguration)
cache = await container.aget(CacheBackend)

Override settings by registering a higher-priority @Provider before ainstall() (equal-priority bindings resolve first-registered):

from providify import Provider


@Provider(singleton=True)
def memcached_cache_settings() -> MemcachedCacheSettings:
    return MemcachedCacheSettings(host=os.environ["MEMCACHED_HOST"], key_prefix="myapp:")


container.provide(memcached_cache_settings)
await container.ainstall(MemcachedCacheConfiguration)

Running tests

uv run pytest varco_memcached/tests/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

varco_memcached-3.1.0.tar.gz (49.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

varco_memcached-3.1.0-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file varco_memcached-3.1.0.tar.gz.

File metadata

  • Download URL: varco_memcached-3.1.0.tar.gz
  • Upload date:
  • Size: 49.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for varco_memcached-3.1.0.tar.gz
Algorithm Hash digest
SHA256 aefcec78255ab212a06a5650a695ca4ec7946bc25240f8df89f0c772cac0f0d0
MD5 8f0cd026e4ef4149bc1706a293d51a6d
BLAKE2b-256 ac593a5b77c75191c19064e4a9769c98207089060680371040fa93151b7da731

See more details on using hashes here.

Provenance

The following attestation bundles were made for varco_memcached-3.1.0.tar.gz:

Publisher: release.yml on edoardoscarpaci/varco

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file varco_memcached-3.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for varco_memcached-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d5d8004a49bd1ae6490618cab7724c788ba08154ec8c7e82cb933802355b9b4
MD5 2428558ac7b084a988d36bc19aa17da4
BLAKE2b-256 9088b23cb2ca702cd29b762a73a2117dd55a848b529ff67341350b83bd7d29af

See more details on using hashes here.

Provenance

The following attestation bundles were made for varco_memcached-3.1.0-py3-none-any.whl:

Publisher: release.yml on edoardoscarpaci/varco

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

3.2.0

2 files

This release

3.1.0 This release

2 files

3.0.0

2 files

1.1.1

2 files

1.1.0

2 files

1.0.6

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page