diff --git a/README.rst b/README.rst index 876d31f..4dec744 100644 --- a/README.rst +++ b/README.rst @@ -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 --------------------------- diff --git a/cachier/core.py b/cachier/core.py index a909915..1e106d4 100644 --- a/cachier/core.py +++ b/cachier/core.py @@ -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))