Skip to content

Bug: ttl_seconds parameter ignored in in-memory RedisCache set() method #572

Description

Description

The set() method in the in-memory RedisCache implementation accepts a ttl_seconds parameter, but this parameter is currently ignored.

def set(self, key: str, value: str, ttl_seconds: int | None = None) -> bool:

Regardless of the provided ttl_seconds, the cache always uses the global self.ttl_seconds value indirectly via timestamp comparison.

Current Behavior

  • Per-key TTL cannot be set
  • All keys share the same TTL
  • Leads to inconsistent behavior compared to Redis

Expected Behavior

  • Allow per-key TTL override
  • Store expiry time per key instead of relying only on insertion timestamp

Proposed Solution

  • Store (value, expiry_time) instead of (value, timestamp)
  • Update all TTL-related methods (get, exists, ttl, etc.)

Impact

  • Improves correctness
  • Aligns behavior closer to Redis
  • Backward compatible

Hello author, I am willing to contribute to this issue. Hopefully the revised approach perform better caching in production over the existing implementation. looking forward.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions