mirror of
https://github.com/python/cpython.git
synced 2026-01-06 07:22:09 +00:00
Issue 13227: Option to make the lru_cache() type specific (suggested by Andrew Koenig).
This commit is contained in:
parent
e3455c026a
commit
cd9fdfd652
5 changed files with 49 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue