fleche
lru_cache on ‘roids.
Submodules
Classes
Type wrapper to mark a function argument as ignored for caching. |
|
Type wrapper to mark a function argument as required for caching. |
Functions
|
Manages the active cache for Fleche. If new_cache is provided, it returns a context manager |
|
|
|
A context manager to add arbitrary tags to results. |
|
A context manager to tag results with a project name. |
|
Cache decorator for functions. |
Package Contents
- fleche.cache(new_cache: None = None, stack: bool = False) fleche.caches.BaseCache[source]
- fleche.cache(new_cache: fleche.caches.BaseCache | str, stack: bool = False) contextlib.AbstractContextManager[None]
Manages the active cache for Fleche. If new_cache is provided, it returns a context manager that sets the cache for the duration of the context. If new_cache is None, it returns the currently active cache.
- Parameters:
new_cache (Optional[BaseCache]) – An optional Cache object to set as the active cache.
stack (bool, default False) – if True, construct a CacheStack, with new_cache at the bottom
- Returns:
The current cache object if new_cache is None, otherwise a context manager to set a new cache.
- Return type:
Union[
BaseCache, AbstractContextManager[None]]
- fleche.meta(*new_metadata: fleche.metadata.MetaData, stack=False)[source]
- fleche.tags(**kwargs)[source]
A context manager to add arbitrary tags to results.
- Parameters:
**kwargs – The tags to add to the results.
- fleche.project(name)[source]
A context manager to tag results with a project name.
- Parameters:
name (str) – The name of the project.
- fleche.fleche(_func=None, *, version: int | None = None, meta: tuple[fleche.metadata.MetaData, Ellipsis] = (), hash_version: bool = True, hash_module: bool = True, hash_code: bool = False, require: None | str | list[str] | tuple[str] = None, ignore: None | str | list[str] | tuple[str] = None, isolate: bool = False)[source]
Cache decorator for functions.
The decorated function is enhanced with helper methods: - .call(*args, **kwargs): Get the :clas:`.Call` object. - .digest(*args, **kwargs): Get the cache key. - .load(*args, **kwargs): Load result from cache. - .contains(*args, **kwargs): Check if result is in cache. - .rerun(*args, **kwargs): Forces reevaluation recursively. The original function is available via .__wrapped__.
- class fleche.Ignored[source]
Type wrapper to mark a function argument as ignored for caching.
Can be used as a type hint:
arg: fleche.Ignoredorarg: fleche.Ignored[int].
- class fleche.Required[source]
Type wrapper to mark a function argument as required for caching.
Arguments marked as required must be explicitly provided by the caller as keyword arguments (i.e. not via their default value) for the result to be cached. This is useful for arguments like random seeds or iteration counts, where using the default value might lead to non-deterministic or otherwise undesirable caching behavior.
This is mainly useful when wrapping third-party functions where you do not control the default arguments.
Can be used as a type hint:
arg: fleche.Requiredorarg: fleche.Required[int].