From f7788c930105b8d5eea8a314894a58236e737f1b Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 25 Nov 2018 16:24:52 -0800 Subject: [PATCH] bpo-35300: Add usage note to the lru_cache() docs (GH-10707) https://bugs.python.org/issue35300 (cherry picked from commit f0e0f2008d160cdd7e5bc02ea61c43f8c7b2b82f) Co-authored-by: Raymond Hettinger --- Doc/library/functools.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index b221a8584a12aaf..41c06c647b78240 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -80,6 +80,11 @@ The :mod:`functools` module defines the following functions: The cache's size limit assures that the cache does not grow without bound on long-running processes such as web servers. + In general, the LRU cache should only be used when you want to reuse + previously computed values. Accordingly, it doesn't make sense to cache + functions with side-effects, functions that need to create distinct mutable + objects on each call, or impure functions such as time() or random(). + Example of an LRU cache for static web content:: @lru_cache(maxsize=32)