API#
- @bamboo_stash.stash(f: Callable[[P], R]) StashedFunction[P, R][source]#
Convenience decorator for when you don’t care about where the cached data is stored.
The first time this function is called, this automatically creates a
Stashobject for you with default arguments. Subsequent calls will re-use that object.The automatically created
Stashobject is intentionally hidden from you. If you need to access attributes such asStash.base_dir, you should explicitly create aStashobject instead.
- class bamboo_stash.Stash(base_dir: PathLike[str] | None = None)[source]#
An object that can be used to decorate functions to transparently cache its calls.
If the chosen directory doesn’t exist, it will be created (along with its parents) the first time a function call is cached to disk.
- Parameters:
base_dir – Directory for storing cached data. If the value is
None(the default), an appropriate cache directory is automatically chosen in the user’s home directory. This automatically chosen value can be seen usingStash.base_dir.
- __call__(f: Callable[[P], R]) StashedFunction[P, R][source]#
Decorator to wrap a function to cache its calls.
You wouldn’t call this method explicitly; this method exists to make the
Stashobject itself callable as a decorator.For example:
from bamboo_stash import Stash stash = Stash() @stash # <-- This line invokes stash.__call__ def my_function(): ...
- class bamboo_stash.StashedFunction(base_dir: Path, f: Callable[[P], R])[source]#
Callable object that wraps your original function.
- path_for(*args: ~typing.~P, **kwargs: ~typing.~P) Path[source]#
File where data for a function call with these arguments should be stored.