summaryrefslogtreecommitdiffstats
path: root/Doc/library/functools.rst
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-10-20 15:57:45 (GMT)
committerRaymond Hettinger <python@rcn.com>2011-10-20 15:57:45 (GMT)
commitcd9fdfd652cdaca959b1c5d4cddf60d90a331b47 (patch)
treef714220e35080ef6ad49bc0a88999483fcb0e14a /Doc/library/functools.rst
parente3455c026afdf5d4448aefde44f7530ea456a9e0 (diff)
downloadcpython-cd9fdfd652cdaca959b1c5d4cddf60d90a331b47.zip
cpython-cd9fdfd652cdaca959b1c5d4cddf60d90a331b47.tar.gz
cpython-cd9fdfd652cdaca959b1c5d4cddf60d90a331b47.tar.bz2
Issue 13227: Option to make the lru_cache() type specific (suggested by Andrew Koenig).
Diffstat (limited to 'Doc/library/functools.rst')
-rw-r--r--Doc/library/functools.rst13
1 files changed, 10 insertions, 3 deletions
diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst
index 2316e80..4eaf54e 100644
--- a/Doc/library/functools.rst
+++ b/Doc/library/functools.rst
@@ -40,7 +40,7 @@ The :mod:`functools` module defines the following functions:
.. versionadded:: 3.2
-.. decorator:: lru_cache(maxsize=100)
+.. decorator:: lru_cache(maxsize=100, typed=False)
Decorator to wrap a function with a memoizing callable that saves up to the
*maxsize* most recent calls. It can save time when an expensive or I/O bound
@@ -52,6 +52,10 @@ The :mod:`functools` module defines the following functions:
If *maxsize* is set to None, the LRU feature is disabled and the cache
can grow without bound.
+ If *typed* is set to True, function arguments of different types will be
+ cached separately. For example, ``f(3)`` and ``f(3.0)`` will be treated
+ as distinct calls with distinct results.
+
To help measure the effectiveness of the cache and tune the *maxsize*
parameter, the wrapped function is instrumented with a :func:`cache_info`
function that returns a :term:`named tuple` showing *hits*, *misses*,
@@ -67,8 +71,8 @@ The :mod:`functools` module defines the following functions:
An `LRU (least recently used) cache
<http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used>`_ works
- best when more recent calls are the best predictors of upcoming calls (for
- example, the most popular articles on a news server tend to change daily).
+ best when the most recent calls are the best predictors of upcoming calls (for
+ example, the most popular articles on a news server tend to change each day).
The cache's size limit assures that the cache does not grow without bound on
long-running processes such as web servers.
@@ -111,6 +115,9 @@ The :mod:`functools` module defines the following functions:
.. versionadded:: 3.2
+ .. versionchanged:: 3.3
+ Added the *typed* option.
+
.. decorator:: total_ordering
Given a class defining one or more rich comparison ordering methods, this