Name | cachemethod JSON |
Version |
1.0.0
JSON |
| download |
home_page | None |
Summary | None |
upload_time | 2024-08-13 18:23:47 |
maintainer | None |
docs_url | None |
author | daniel sonbolian |
requires_python | <4.0,>=3.10 |
license | None |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# cachemethod
python's missing cache functionality, you can cache a regular function
you can cache `staticmethod` and `classmethod` but you can't really cache a method that takes `self`.
```console
pip3 install cachemethod
```
## why can't I use cache on a method that takes self?
python `cache` doesn't actually stores the hash of the *args and *kwargs (including `self`), but it
puts it into a tuple (which is hashable) and that tuple is used as a key in the cache `dict`, thus
storing the reference to `self` in that tuple causes the instance to be a live until the cache is cleared
or it runs of our space (if you use `lru_cache`)
## why not just hash the items then?
the default `hash` implementation for classes uses the allocated memory for instances,
so if an instance memory gets freed, the `cache` is not really valid anymore but it is still
in the `cache` dict, so instance that was created on the same memory and passed the same arguments
can hit the cache and cause unexpected results
## how this package solves the issue
it creates a `seed` which is a random integer and attaches it to the instance, based on that `seed` caching is done
not relying on the class `hash` and not storing references
Raw data
{
"_id": null,
"home_page": null,
"name": "cachemethod",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": null,
"author": "daniel sonbolian",
"author_email": "dsal3389@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/41/b6/72c7093d914e9608dd18a17769f8bc3cdafaa713631dc6d206e154a5ecbc/cachemethod-1.0.0.tar.gz",
"platform": null,
"description": "# cachemethod\npython's missing cache functionality, you can cache a regular function\nyou can cache `staticmethod` and `classmethod` but you can't really cache a method that takes `self`.\n\n```console\npip3 install cachemethod\n```\n\n## why can't I use cache on a method that takes self?\npython `cache` doesn't actually stores the hash of the *args and *kwargs (including `self`), but it\nputs it into a tuple (which is hashable) and that tuple is used as a key in the cache `dict`, thus\nstoring the reference to `self` in that tuple causes the instance to be a live until the cache is cleared\nor it runs of our space (if you use `lru_cache`)\n\n## why not just hash the items then?\nthe default `hash` implementation for classes uses the allocated memory for instances,\nso if an instance memory gets freed, the `cache` is not really valid anymore but it is still\nin the `cache` dict, so instance that was created on the same memory and passed the same arguments\ncan hit the cache and cause unexpected results\n\n## how this package solves the issue\nit creates a `seed` which is a random integer and attaches it to the instance, based on that `seed` caching is done\nnot relying on the class `hash` and not storing references\n\n",
"bugtrack_url": null,
"license": null,
"summary": null,
"version": "1.0.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2c89240087e484a6f3b0c5645f071f8378d954cd1d80aadf6e88cbb83dda9bb4",
"md5": "c09c160d66c82dfba37dd0ed2009c3df",
"sha256": "9fa1caac59184dbd3d9b29fb87ea2f8b50bdcf9f1e8e43d36207ed3b0ff2602c"
},
"downloads": -1,
"filename": "cachemethod-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c09c160d66c82dfba37dd0ed2009c3df",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 3061,
"upload_time": "2024-08-13T18:23:46",
"upload_time_iso_8601": "2024-08-13T18:23:46.296343Z",
"url": "https://files.pythonhosted.org/packages/2c/89/240087e484a6f3b0c5645f071f8378d954cd1d80aadf6e88cbb83dda9bb4/cachemethod-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "41b672c7093d914e9608dd18a17769f8bc3cdafaa713631dc6d206e154a5ecbc",
"md5": "be4bb20a99cb403c5f9ec1887c11472c",
"sha256": "5da4f883532ec737d3838779933eb19967e53ccaa2012844783751369b86c65a"
},
"downloads": -1,
"filename": "cachemethod-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "be4bb20a99cb403c5f9ec1887c11472c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 2701,
"upload_time": "2024-08-13T18:23:47",
"upload_time_iso_8601": "2024-08-13T18:23:47.718550Z",
"url": "https://files.pythonhosted.org/packages/41/b6/72c7093d914e9608dd18a17769f8bc3cdafaa713631dc6d206e154a5ecbc/cachemethod-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-13 18:23:47",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "cachemethod"
}