16/37
Part 4 of 6 · Time limitsLearn and do
Expire entries by time, with a clock you pass in
Now the second question: when does an entry stop being valid? Each entry gets a ttl in seconds when it's written.
Store when an entry expires: it's live while t <= now < t + ttl
024681012
a
● the start is in. ○ the end is out.
0 <= 10 < 10 is false, so at 10 it's gone.
Store when it expires, not how long it lives. Save expires_at = now + ttl with the value. A read then compares one number with the current time. ttl=None stores expires_at=None, an entry that never expires.
Decide the boundary before you write a line. An entry written at time t with time to live ttl is live while t <= now < t + ttl. So the entry above is live at 9, and at exactly 10 it's gone. The first practice problem uses the same rule. Get it backwards and every test at the boundary fails.
a is written at time 0 with ttl=10, then again at time 8 with ttl=10. When does it expire?
Pick an answer above to see the rest