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.
Description
The set() method in the in-memory RedisCache implementation accepts a ttl_seconds parameter, but this parameter is currently ignored.
Regardless of the provided ttl_seconds, the cache always uses the global self.ttl_seconds value indirectly via timestamp comparison.
Current Behavior
Expected Behavior
Proposed Solution
Impact
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.