hash_params documentation added

This commit is contained in:
Shay Palachy
2020-03-20 15:08:54 +02:00
parent aa735e108e
commit 63d3b6d6d7
2 changed files with 16 additions and 4 deletions
+12
View File
@@ -130,6 +130,18 @@ Sometimes you may want your function to trigger a calculation when it encounters
Further function calls made while the calculation is being performed will not trigger redundant calculations.
Working with unhashable arguments
---------------------------------
As mentioned above, The positional and keyword arguments to the wrapped function must be hashable (i.e. Python's immutable built-in objects, not mutable containers). To get around this limitation the ``hash_params`` parameter of the ``cachier`` decorator can be provided with a callable that gets the args and kwargs from the decorated function and returns a hash key for them.
.. code-block:: python
@cachier(hash_params=hash_my_custom_class)
def calculate_super_complex_stuff(custom_obj):
# amazing code goes here
Per-function call arguments
---------------------------
+4 -4
View File
@@ -114,10 +114,10 @@ def cachier(
The running process must have running permissions to this folder. If
not provided, a default directory at `~/.cachier/` is used.
hash_params : callable, optional
A callable that takes args and kwargs from main function and returns
a hash key of these params. If unset, default transformation is
applied. It is valuable and works as workaround in scenarios
that positional and keyword arguments are not hashable.
A callable that gets the args and kwargs from the decorated function
and returns a hash key for them. This parameter can be used to enable
the use of cachier with functions that get arguments that are not
automatically hashable by Python.
"""
# print('Inside the wrapper maker')
# print('mongetter={}'.format(mongetter))