Skip to content
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

DOC: Document cache hit function #1343

Merged
merged 2 commits into from
Sep 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 21 additions & 4 deletions doc/memory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Using with `numpy`

The original motivation behind the `Memory` context was to have a
memoize-like pattern on numpy arrays. `Memory` uses fast cryptographic
hashing of the input arguments to check if they have been computed;
hashing of the input arguments to check if they have been computed.

An example
~~~~~~~~~~
Expand Down Expand Up @@ -242,7 +242,7 @@ python interpreter.


Gotchas
--------
-------

* **Across sessions, function cache is identified by the function's name**.
Thus assigning the same name to different functions, their cache will
Expand Down Expand Up @@ -422,9 +422,26 @@ Reference documentation of the `Memory` class
Useful methods of decorated functions
-------------------------------------

Function decorated by :meth:`Memory.cache` are :class:`MemorizedFunc`
Functions decorated by :meth:`Memory.cache` are :class:`MemorizedFunc`
objects that, in addition of behaving like normal functions, expose
methods useful for cache exploration and management.
methods useful for cache exploration and management. For example, you can
use :meth:`func.check_call_in_cache <MemorizedFunc.check_call_in_cache>` to
check if a cache hit will occur for a decorated ``func`` given a set of inputs
without actually needing to call the function itself::

>>> @memory.cache
... def func(x):
... print('Running func(%s)' % x)
... return x
>>> type(func)
<class 'joblib.memory.MemorizedFunc'>
>>> func(1)
Running func(1)
1
>>> func.check_call_in_cache(1) # cache hit
True
>>> func.check_call_in_cache(2) # cache miss
False

.. autoclass:: MemorizedFunc
:members: __init__, call, clear, check_call_in_cache
Expand Down