allescacher


Nameallescacher JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/allescacher
SummaryLike @functools.cache / @functools.lru_cache but with non-hashable objects
upload_time2023-09-20 03:50:32
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords cache @functools.lru_cache @functools.cache
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# 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.


```python

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.

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/allescacher",
    "name": "allescacher",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "cache,@functools.lru_cache,@functools.cache",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/44/f5/98f691969d5c795802e444c83891497685c10ab9ba94d4c00310f41169bb/allescacher-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# Like @functools.cache / @functools.lru_cache but with non-hashable objects\r\n\r\n## Tested against Windows 10 / Python 3.11 / Anaconda\r\n\r\n### pip install allescacher\r\n\r\n\r\n## Cache Everything Decorator\r\n\r\nThis module provides a decorator `cache_everything` \r\nthat can be used to cache the results of function calls.\r\nIt uses a dictionary to store cached results and allows \r\ncustomization of cache size and eviction strategy.\r\nUnlike some caching mechanisms that rely on hashable arguments,\r\nthe \"cache_everything\" decorator accepts a wide range\r\nof argument types, including non-hashable objects,\r\ncomplex data structures, and even functions as arguments.\r\nThis means you can cache the results of functions that\r\noperate on mutable or unhashable input data,\r\nmaking it suitable for a broader set of use cases.\r\nFor example, if your function operates on lists,\r\ndictionaries, or custom objects, you can still\r\napply the decorator without the need to convert\r\nthese inputs into hashable forms. This flexibility simplifies\r\nthe caching process and allows you to cache results\r\nefficiently for functions that work with diverse and\r\npotentially non-hashable data.\r\n\r\n\r\n```python\r\n\r\nUsage:\r\n\tTo cache the results of a function, decorate it with `@cache_everything`.\r\n\r\nExample:\r\n\timport numpy as np\r\n\timport random\r\n\tfrom allescacher import cache_everything, cache_dict_module\r\n\r\n\tcache_dict_module.maxsize = None\r\n\tcache_dict_module.del_min_used = True\r\n\r\n\t@cache_everything\r\n\tdef getnparray(l):\r\n\t\treturn np.array(l) / 10 * 3\r\n\r\n\tdone = []\r\n\tfor _ in range(1000):\r\n\t\tdone.append(\r\n\t\t\tgetnparray([random.randint(0, 10) for x in range(random.randint(1, 5))])\r\n\t\t)\r\n\r\n\t# Clear the cache for the 'getnparray' function\r\n\tcache_dict_module.cache_dict[getnparray.__qualname__].clear()\r\n\r\nModule Variables:\r\n\t- `cache_dict_module`: A module-level variable used to store the cache dictionary.\r\n\t- `cache_dict_module.cache_dict`: The cache dictionary where cached results are stored.\r\n\t- `cache_dict_module.maxsize`: The maximum size of the cache (None for unlimited).\r\n\t- `cache_dict_module.del_min_used`: A flag to determine whether to evict the least-used cache entry.\r\n\r\nDecorator:\r\n\t- `@cache_everything`: Decorates a function to enable caching of its results.\r\n\r\nFunctions:\r\n\t- `cache_everything(f_py=None)`: The decorator function that can be used to cache function results.\r\n\r\nThis module provides a flexible caching mechanism that can be applied to functions to improve performance by\r\nretrieving cached results for known input arguments, reducing the need for redundant computations.\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Like @functools.cache / @functools.lru_cache but with non-hashable objects",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/allescacher"
    },
    "split_keywords": [
        "cache",
        "@functools.lru_cache",
        "@functools.cache"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "46f9ebaa0f6055355f851dbf712d896b9ce6affaecec43fbe0fd1f0ee4de72f1",
                "md5": "272e0ae291dcedbaa19f24a5329886cc",
                "sha256": "29486f4bee376868f6152541f2143455bd4292d5be24fc7a5a76b839d48e4ffa"
            },
            "downloads": -1,
            "filename": "allescacher-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "272e0ae291dcedbaa19f24a5329886cc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6518,
            "upload_time": "2023-09-20T03:50:31",
            "upload_time_iso_8601": "2023-09-20T03:50:31.020575Z",
            "url": "https://files.pythonhosted.org/packages/46/f9/ebaa0f6055355f851dbf712d896b9ce6affaecec43fbe0fd1f0ee4de72f1/allescacher-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "44f598f691969d5c795802e444c83891497685c10ab9ba94d4c00310f41169bb",
                "md5": "20fb2093b143b11887a668d46a8ddc37",
                "sha256": "0780b7996b72c4c7613c61f426aeb0daa071e4e2d0f435b7e077cd7d0159013b"
            },
            "downloads": -1,
            "filename": "allescacher-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "20fb2093b143b11887a668d46a8ddc37",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4438,
            "upload_time": "2023-09-20T03:50:32",
            "upload_time_iso_8601": "2023-09-20T03:50:32.933587Z",
            "url": "https://files.pythonhosted.org/packages/44/f5/98f691969d5c795802e444c83891497685c10ab9ba94d4c00310f41169bb/allescacher-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-20 03:50:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "allescacher",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "allescacher"
}
        
Elapsed time: 0.19958s