From 4dbfc373fc725e9aec457a7ff9046688aa8d683a Mon Sep 17 00:00:00 2001 From: Ilya Nikolaev <65247719+ilya-nikolaev@users.noreply.github.com> Date: Sat, 6 Jun 2026 01:42:59 +0300 Subject: [PATCH] Use `time.monotonic` in OrderedDict LRU cache example (GH-150986) (cherry picked from commit ea4c85552bb7883e1d6c808281c1f46aca86aeab) Co-authored-by: Ilya Nikolaev <65247719+ilya-nikolaev@users.noreply.github.com> --- Doc/library/collections.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 25e4a71b03c6c8..0c727b71cf4d4b 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -1233,7 +1233,7 @@ variants of :func:`functools.lru_cache`: .. testcode:: from collections import OrderedDict - from time import time + from time import monotonic class TimeBoundedLRU: "LRU Cache that invalidates and refreshes old entries." @@ -1248,10 +1248,10 @@ variants of :func:`functools.lru_cache`: if args in self.cache: self.cache.move_to_end(args) timestamp, result = self.cache[args] - if time() - timestamp <= self.maxage: + if monotonic() - timestamp <= self.maxage: return result result = self.func(*args) - self.cache[args] = time(), result + self.cache[args] = monotonic(), result if len(self.cache) > self.maxsize: self.cache.popitem(last=False) return result