Skip to content

CacheManager.get_or_set returns a different value on a miss than on a hit #235

Description

@allen0099

On a miss, get_or_set returns the factory's value as is; on a hit, the JSON-decoded one. The two differ whenever JSON changes the value:

miss: (1, 2)      hit: [1, 2]
miss: {1: 'a'}    hit: {'1': 'a'}

The first caller sees a tuple and int keys, later callers a list and str keys, so type and key-lookup bugs only appear once the value is cached. For values JSON cannot encode (datetime, Decimal, UUID, pydantic models), the TypeError comes after the possibly expensive factory has run.

Proposal

Return the decoded value on a miss too, so both paths agree, and document the JSON round-trip rules in APP_CACHE.md. Typed reads are a separate enhancement.

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

    bugSomething isn't workingcache-managerApplication-level CacheManager

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions