CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pylibmc

Quick and small memcached client for Python

86

1.03x
Overview
Eval results
Files

task.mdevals/scenario-7/

Prefixed Bulk Cache

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.

Capabilities

Bulk store with shared prefix

  • Storing multiple user settings at once (ids u1, u2) and then reading those ids returns both values keyed by the original ids; no prefixed keys are exposed to callers. @test

Bulk fetch ignoring misses

  • Requesting ids a, b, missing after only a and b are stored returns just a and b; absent entries are omitted rather than set to null/None. @test

Prefix isolation

  • When an unprefixed key session123 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

Implementation

@generates

API

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)."""

Dependencies { .dependencies }

pylibmc { .dependency }

Memcached client providing bulk operations and transparent key prefix handling.

Install with Tessl CLI

npx tessl i tessl/pypi-pylibmc

tile.json