varco-memcached
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
bytes—aiomcacherequires byte keys;varco_memcachedencodes the prefixed key as UTF-8 internally. - No native key enumeration. Memcached has no
SCAN-equivalent command.clear()only removes keys written by thisMemcachedCacheinstance 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'sflush_all()for a full flush (affects every client sharing that server). - No native
exists(). It performs agetand checks forNone— a full round trip, though deserialization is skipped. - TTL semantics differ. Memcached's
exptimeof0means "never expire" — the opposite convention from a bare RedisSETwith 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aefcec78255ab212a06a5650a695ca4ec7946bc25240f8df89f0c772cac0f0d0
|
|
| MD5 |
8f0cd026e4ef4149bc1706a293d51a6d
|
|
| BLAKE2b-256 |
ac593a5b77c75191c19064e4a9769c98207089060680371040fa93151b7da731
|
Provenance
The following attestation bundles were made for varco_memcached-3.1.0.tar.gz:
Publisher:
release.yml on edoardoscarpaci/varco
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
varco_memcached-3.1.0.tar.gz -
Subject digest:
aefcec78255ab212a06a5650a695ca4ec7946bc25240f8df89f0c772cac0f0d0 - Sigstore transparency entry: 2727617335
- Sigstore integration time:
-
Permalink:
edoardoscarpaci/varco@68ee1c0583b9bdcadca9dafa559583b48a5d222f -
Branch / Tag:
refs/tags/v3.1.0 - Owner: https://github.com/edoardoscarpaci
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@68ee1c0583b9bdcadca9dafa559583b48a5d222f -
Trigger Event:
push
-
Statement type:
File details
Details for the file varco_memcached-3.1.0-py3-none-any.whl.
File metadata
- Download URL: varco_memcached-3.1.0-py3-none-any.whl
- Upload date:
- Size: 37.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d5d8004a49bd1ae6490618cab7724c788ba08154ec8c7e82cb933802355b9b4
|
|
| MD5 |
2428558ac7b084a988d36bc19aa17da4
|
|
| BLAKE2b-256 |
9088b23cb2ca702cd29b762a73a2117dd55a848b529ff67341350b83bd7d29af
|
Provenance
The following attestation bundles were made for varco_memcached-3.1.0-py3-none-any.whl:
Publisher:
release.yml on edoardoscarpaci/varco
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
varco_memcached-3.1.0-py3-none-any.whl -
Subject digest:
5d5d8004a49bd1ae6490618cab7724c788ba08154ec8c7e82cb933802355b9b4 - Sigstore transparency entry: 2727617437
- Sigstore integration time:
-
Permalink:
edoardoscarpaci/varco@68ee1c0583b9bdcadca9dafa559583b48a5d222f -
Branch / Tag:
refs/tags/v3.1.0 - Owner: https://github.com/edoardoscarpaci
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@68ee1c0583b9bdcadca9dafa559583b48a5d222f -
Trigger Event:
push
-
Statement type: