mirror of
https://github.com/wassname/cachier.git
synced 2026-09-09 11:19:08 +08:00
hash_params documentation added
This commit is contained in:
+12
@@ -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
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user