]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Use `time.monotonic` in OrderedDict LRU cache example (#150986)
authorIlya Nikolaev <65247719+ilya-nikolaev@users.noreply.github.com>
Fri, 5 Jun 2026 22:42:59 +0000 (01:42 +0300)
committerGitHub <noreply@github.com>
Fri, 5 Jun 2026 22:42:59 +0000 (01:42 +0300)
Doc/library/collections.rst

index bd04063232e527e0c27113327f6531e3666619af..d09a6c92bbd37dccd2d266489810876c08667a3c 100644 (file)
@@ -1233,7 +1233,7 @@ variants of :deco:`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 :deco:`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