← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Implement a key-value cache where each entry expires after a specified time-to-live (TTL).
`python class AutoExpireCache: def set(key: str, value: any, ttl_ms: int) -> bool: # Set key with value that expires after ttl_ms milliseconds # Return True if key didn't exist, False if updating existing key
def get(key: str) -> any:
# Return value if key exists and not expired, otherwise None
def count() -> int:
# Return count of non-expired keys
`
Follow-ups: Lazy delete vs background cleanup, LRU eviction when memory full.