TTL Cache
Asked at Netflix· Screen
Reported by the problem's creator, not verified
Design an in-memory cache keyed by strings, holding integer values. Every method takes the current timestamp at as its first argument, and timestamps never decrease between calls. Each test drives one TTLCache() instance through a sequence of calls and records every call's return value (None for methods that return nothing).
Examples
Example 1
Input: init =
[], operations =[["put",[1,"a",10,5]],["get",[2,"a"]],["get",[5,"a"]],["get",[6,"a"]],["count",[6]],["put",[7,"b",0,3]],["get",[8,"b"]],["put",[9,"b",7,1]],["get",[9,"b"]],["get",[10,"b"]],["count",[10]]]Output:
[null,10,10,null,0,null,0,null,7,null,0]Explanation:
ais stored at time 1 withttl5, so it is live through time 5 and expired at 6.bis stored at 7, replaced at 9 with a one-unitttl, readable at 9 and gone at 10.countsees only live entries.