Skip to content

Commit 63e1256

Browse files
committed
use time.monotonic in OrderedDict LRU cache example
1 parent 6544bf4 commit 63e1256

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

Doc/library/collections.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ variants of :deco:`functools.lru_cache`:
12331233
.. testcode::
12341234

12351235
from collections import OrderedDict
1236-
from time import time
1236+
from time import monotonic
12371237

12381238
class TimeBoundedLRU:
12391239
"LRU Cache that invalidates and refreshes old entries."
@@ -1248,10 +1248,10 @@ variants of :deco:`functools.lru_cache`:
12481248
if args in self.cache:
12491249
self.cache.move_to_end(args)
12501250
timestamp, result = self.cache[args]
1251-
if time() - timestamp <= self.maxage:
1251+
if monotonic() - timestamp <= self.maxage:
12521252
return result
12531253
result = self.func(*args)
1254-
self.cache[args] = time(), result
1254+
self.cache[args] = monotonic(), result
12551255
if len(self.cache) > self.maxsize:
12561256
self.cache.popitem(last=False)
12571257
return result

0 commit comments

Comments
 (0)