Skip to main content

Like @functools.cache / @functools.lru_cache but with non-hashable objects

Tested against Windows 10 / Python 3.11 / Anaconda

pip install allescacher

Cache Everything Decorator

This module provides a decorator cache_everything that can be used to cache the results of function calls. It uses a dictionary to store cached results and allows customization of cache size and eviction strategy. Unlike some caching mechanisms that rely on hashable arguments, the "cache_everything" decorator accepts a wide range of argument types, including non-hashable objects, complex data structures, and even functions as arguments. This means you can cache the results of functions that operate on mutable or unhashable input data, making it suitable for a broader set of use cases. For example, if your function operates on lists, dictionaries, or custom objects, you can still apply the decorator without the need to convert these inputs into hashable forms. This flexibility simplifies the caching process and allows you to cache results efficiently for functions that work with diverse and potentially non-hashable data.

Usage:
	To cache the results of a function, decorate it with `@cache_everything`.

Example:
	import numpy as np
	import random
	from allescacher import cache_everything, cache_dict_module

	cache_dict_module.maxsize = None
	cache_dict_module.del_min_used = True

	@cache_everything
	def getnparray(l):
		return np.array(l) / 10 * 3

	done = []
	for _ in range(1000):
		done.append(
			getnparray([random.randint(0, 10) for x in range(random.randint(1, 5))])
		)

	# Clear the cache for the 'getnparray' function
	cache_dict_module.cache_dict[getnparray.__qualname__].clear()

Module Variables:
	- `cache_dict_module`: A module-level variable used to store the cache dictionary.
	- `cache_dict_module.cache_dict`: The cache dictionary where cached results are stored.
	- `cache_dict_module.maxsize`: The maximum size of the cache (None for unlimited).
	- `cache_dict_module.del_min_used`: A flag to determine whether to evict the least-used cache entry.

Decorator:
	- `@cache_everything`: Decorates a function to enable caching of its results.

Functions:
	- `cache_everything(f_py=None)`: The decorator function that can be used to cache function results.

This module provides a flexible caching mechanism that can be applied to functions to improve performance by
retrieving cached results for known input arguments, reducing the need for redundant computations.

Metadata

Release files for allescacher 0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for allescacher 0.10
File Size Uploaded Provenance Actions
allescacher-0.10.tar.gz 4.4 kB Without provenance Details for allescacher-0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for allescacher 0.10
File Interpreter ABI Platform Actions
allescacher-0.10-py3-none-any.whl Python 3 none any Details for allescacher-0.10-py3-none-any.whl

Total release size: 11.0 kB

Release files / allescacher-0.10.tar.gz

Download URL allescacher-0.10.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0780b7996b72c4c7613c61f426aeb0daa071e4e2d0f435b7e077cd7d0159013b
BLAKE2b-256 checksum
How to use checksums
44f598f691969d5c795802e444c83891497685c10ab9ba94d4c00310f41169bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / allescacher-0.10-py3-none-any.whl

Download URL allescacher-0.10-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29486f4bee376868f6152541f2143455bd4292d5be24fc7a5a76b839d48e4ffa
BLAKE2b-256 checksum
How to use checksums
46f9ebaa0f6055355f851dbf712d896b9ce6affaecec43fbe0fd1f0ee4de72f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Security for allescacher 0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page