Skip to content

Commit b9ea60c

Browse files
[3.13] Use time.monotonic in OrderedDict LRU cache example (GH-150986) (#150993)
Use `time.monotonic` in OrderedDict LRU cache example (GH-150986) (cherry picked from commit ea4c855) Co-authored-by: Ilya Nikolaev <65247719+ilya-nikolaev@users.noreply.github.com>
1 parent fd1b5c6 commit b9ea60c

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
@@ -1229,7 +1229,7 @@ variants of :func:`functools.lru_cache`:
12291229
.. testcode::
12301230

12311231
from collections import OrderedDict
1232-
from time import time
1232+
from time import monotonic
12331233

12341234
class TimeBoundedLRU:
12351235
"LRU Cache that invalidates and refreshes old entries."
@@ -1244,10 +1244,10 @@ variants of :func:`functools.lru_cache`:
12441244
if args in self.cache:
12451245
self.cache.move_to_end(args)
12461246
timestamp, result = self.cache[args]
1247-
if time() - timestamp <= self.maxage:
1247+
if monotonic() - timestamp <= self.maxage:
12481248
return result
12491249
result = self.func(*args)
1250-
self.cache[args] = time(), result
1250+
self.cache[args] = monotonic(), result
12511251
if len(self.cache) > self.maxsize:
12521252
self.cache.popitem(last=False)
12531253
return result

0 commit comments

Comments
 (0)