Skip to content

GH-103475: cache() and lru_cache() do not have a "call once" guarantee #103669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Doc/library/functools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ The :mod:`functools` module defines the following functions:
>>> factorial(12) # makes two new recursive calls, the other 10 are cached
479001600

The cache is threadsafe so the wrapped function can be used in multiple
threads.
The cache is threadsafe so that the wrapped function can be used in
multiple threads. This means that the underlying data structure will
remain coherent during concurrent updates.

It is possible for the wrapped function to be called more than once if
another thread makes an additional call before the initial call has been
completed and cached.

.. versionadded:: 3.9

Expand Down Expand Up @@ -159,8 +164,13 @@ The :mod:`functools` module defines the following functions:
*maxsize* most recent calls. It can save time when an expensive or I/O bound
function is periodically called with the same arguments.

The cache is threadsafe so the wrapped function can be used in multiple
threads.
The cache is threadsafe so that the wrapped function can be used in
multiple threads. This means that the underlying data structure will
remain coherent during concurrent updates.

It is possible for the wrapped function to be called more than once if
another thread makes an additional call before the initial call has been
completed and cached.

Since a dictionary is used to cache results, the positional and keyword
arguments to the function must be :term:`hashable`.
Expand Down