tessl install tessl/pypi-pylibmc@1.6.0Quick and small memcached client for Python
Agent Success
Agent success rate when using this tile
86%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.04x
Baseline
Agent success rate without this tile
83%
Create a small cache helper that batches reads and writes for a group of keys while automatically applying a shared prefix so callers never handle namespacing themselves.
u1, u2) and then reading those ids returns both values keyed by the original ids; no prefixed keys are exposed to callers. @testa, b, missing after only a and b are stored returns just a and b; absent entries are omitted rather than set to null/None. @testsession123 already exists with one value, using the helper with prefix sess: to store and fetch session123 returns only the namespaced value, demonstrating isolation between prefixed and unprefixed keys. @test@generates
from typing import Any, Dict, Iterable, List, Optional
class PrefixedCache:
def __init__(self, client: Any, prefix: str, default_ttl: int = 0) -> None:
"""Wrap a cache client, applying `prefix` to every stored/fetched key."""
def store_all(self, items: Dict[str, Any], ttl: Optional[int] = None) -> List[str]:
"""Persist a mapping of ids to values with the shared prefix; returns ids that failed to store."""
def fetch_existing(self, ids: Iterable[str]) -> Dict[str, Any]:
"""Fetch multiple ids in one call, returning only the ids found (without the prefix)."""Memcached client providing bulk operations and transparent key prefix handling.