derivkit.utils.caching module#

Provides wrap_input_cache().

derivkit.utils.caching.wrap_input_cache(function: Callable[[int | float | Sequence[float] | ndarray], Any], *, number_decimal_places: int | None = None, maxsize: int | None = 4096, copy: bool = True) Callable[[int | float | Sequence[float] | ndarray], Any]#

Wrap a callable with an input-based LRU cache.

This wrapper supports both scalar and array-like numeric inputs. Cache keys are built from normalized inputs, with optional rounding applied before hashing. Cached NumPy arrays are always stored as copies to protect the cache from accidental mutation.

Parameters:
  • function – Function to cache.

  • number_decimal_places – Decimal places used when constructing the cache key. If None, exact input values are used.

  • maxsize – Maximum size of the LRU cache.

  • copy – If True, return copies of cached NumPy array outputs.

Returns:

Wrapped callable with cache_info and cache_clear attached.