Skip to content

Counter detection differs between backends #111

Description

@allen0099

Problem

  • counter_value() (types.py) parses int(entry.content) without checking fingerprint == COUNTER_FINGERPRINT. On the Memory backend (and the base fallback), increment() on a cached response whose body is 42 returns 43 and overwrites it. Redis and Memcached raise CacheXError, as the base docstring documents.
  • set(k, counter_entry(5)) followed by increment(k) works on Memory but raises on Redis/Memcached, which store the entry as a JSON document.
  • codec._as_counter uses int(raw), which accepts whitespace and underscores (b" 7 ", b"1_0").

Proposal

Require the counter fingerprint in counter_value, use a strict ^-?\d+$ check in the codec, and optionally store counter_entry values as bare integers on Redis/Memcached.

Not breaking beyond these edge cases.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendsCache backends and their atomic primitivesbugSomething isn't working

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions