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-5/

Conditional Cache Journal

A helper that relies on memcached's conditional write and string concatenation primitives to manage text entries without race-prone read-modify-write cycles.

Capabilities

Initialize entry only when absent

  • Starting the journal with seed text stores it only if the key is missing and returns True; calling it again leaves the existing value untouched and returns False. @test

Replace only when present

  • Overwriting with new text succeeds only when the key already exists and returns True; attempting on a missing key returns False without creating the entry. @test

Append message

  • Appending "second" to an existing entry "first" results in "first\nsecond" through a direct concatenation primitive rather than fetching and rewriting the value. @test

Prepend banner

  • Prepending "[HDR]" to an existing entry "body" results in "[HDR]body" while leaving the remainder intact. @test

Implementation

@generates

API

from typing import Any

class CacheJournal:
    def __init__(self, client: Any, default_ttl: int | None = None):
        ...

    def initialize(self, key: str, seed: str, ttl: int | None = None) -> bool:
        ...

    def overwrite_existing(self, key: str, text: str, ttl: int | None = None) -> bool:
        ...

    def append_entry(self, key: str, text: str) -> bool:
        ...

    def prepend_banner(self, key: str, banner: str) -> bool:
        ...

Dependencies { .dependencies }

pylibmc { .dependency }

Memcached client providing conditional writes and in-place string concatenation.

Install with Tessl CLI

npx tessl i tessl/pypi-pylibmc

tile.json