django-cache-helper
===================
[![PyPI](https://img.shields.io/pypi/v/django-cache-helper?color=green)](https://pypi.org/project/django-cache-helper/)
[![Test Suite](https://github.com/ycharts/django_cache_helper/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/ycharts/django_cache_helper/actions/workflows/main.yml)
[![Coverage Status](https://coveralls.io/repos/github/ycharts/django_cache_helper/badge.svg?branch=master)](https://coveralls.io/github/ycharts/django_cache_helper?branch=master)
## Overview
django-cache-helper is a simple tool for making caching functions, methods, and class methods a little bit easier.
It is largely based off of django-cache-utils, however, since cache-utils did not support caching model methods by instance and carried other features I didn't need, django-cache-helper was created.
In order to cache and invalidate a function/method/class_method/static_method:
## Support
| Python |
|--------|
| 3.7, 3.8, 3.9, 3.10 |
#### How to Cache
```python
# Caching a function
@cached(60*60) # 60 Minutes
def foo(bar):
return bar
class Incrementer:
@cached_instance_method(60 * 60)
def instance_increment_by(self, num):
return num
@classmethod
@cached_class_method(60 * 60)
def class_increment_by(cls, num):
return num
@staticmethod
@cached(60 * 60)
def get_datetime():
return datetime.utcnow()
```
#### How to invalidate a cache
```python
foo(1)
foo.invalidate(1)
Incrementer.instance_increment_by(1)
Incrementer.instance_increment_by.invalidate(1)
Incrementer.class_increment_by(1)
Incrementer.class_increment_by.invalidate(1)
Incrementer.get_datetime()
Incrementer.get_datetime.invalidate()
```
## Contributors ✨
Thanks goes to these wonderful people.
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><img src="https://avatars.githubusercontent.com/u/2000316?v=4" width="100px;" alt="Kevin Fox"/><br /><sub><b>Kevin Fox</b></sub></td>
<td align="center"><img src="https://avatars.githubusercontent.com/u/3022071?v=4" width="100px;" alt="Tom Jakeway"/><br /><sub><b>Tom Jakeway</b></sub></td>
<td align="center"><img src="https://avatars.githubusercontent.com/u/83293?v=4" width="100px;" alt="Ara Anjargolian"/><br /><sub><b>Ara Anjargolian</b></sub></td>
<td align="center"><img src="https://avatars.githubusercontent.com/u/15602942?v=4" width="100px;" alt="Hyuckin David Lim"/><br /><sub><b>Hyuckin David Lim</b></sub></td>
<td align="center"><img src="https://avatars.githubusercontent.com/u/1248116?v=4" width="100px;" alt="James"/><br /><sub><b>James</b></sub></td>
</tr>
</table>
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
Raw data
{
"_id": null,
"home_page": null,
"name": "django-cache-helper",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "cache, django",
"author": null,
"author_email": "YCharts <developers@ycharts.com>",
"download_url": "https://files.pythonhosted.org/packages/01/3c/d781a47aba792c130866048113a7712b518b8836efdb18785db9e39e88c6/django_cache_helper-1.0.7.tar.gz",
"platform": null,
"description": "django-cache-helper\n===================\n\n \n[![PyPI](https://img.shields.io/pypi/v/django-cache-helper?color=green)](https://pypi.org/project/django-cache-helper/)\n[![Test Suite](https://github.com/ycharts/django_cache_helper/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/ycharts/django_cache_helper/actions/workflows/main.yml)\n[![Coverage Status](https://coveralls.io/repos/github/ycharts/django_cache_helper/badge.svg?branch=master)](https://coveralls.io/github/ycharts/django_cache_helper?branch=master)\n\n## Overview\ndjango-cache-helper is a simple tool for making caching functions, methods, and class methods a little bit easier.\nIt is largely based off of django-cache-utils, however, since cache-utils did not support caching model methods by instance and carried other features I didn't need, django-cache-helper was created.\n\nIn order to cache and invalidate a function/method/class_method/static_method:\n\n## Support\n\n| Python |\n|--------|\n| 3.7, 3.8, 3.9, 3.10 |\n\n\n#### How to Cache\n\n```python\n# Caching a function\n@cached(60*60) # 60 Minutes\ndef foo(bar):\n\treturn bar\n\nclass Incrementer:\n\n @cached_instance_method(60 * 60)\n def instance_increment_by(self, num):\n return num\n\n @classmethod\n @cached_class_method(60 * 60)\n def class_increment_by(cls, num):\n return num\n\n @staticmethod\n @cached(60 * 60)\n def get_datetime():\n return datetime.utcnow()\n```\n\n#### How to invalidate a cache\n\n```python\n\nfoo(1)\nfoo.invalidate(1)\n\nIncrementer.instance_increment_by(1)\nIncrementer.instance_increment_by.invalidate(1)\n\nIncrementer.class_increment_by(1)\nIncrementer.class_increment_by.invalidate(1)\n\nIncrementer.get_datetime()\nIncrementer.get_datetime.invalidate()\n```\n\n\n## Contributors \u2728\n\nThanks goes to these wonderful people.\n\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- prettier-ignore-start -->\n<!-- markdownlint-disable -->\n<table>\n <tr>\n <td align=\"center\"><img src=\"https://avatars.githubusercontent.com/u/2000316?v=4\" width=\"100px;\" alt=\"Kevin Fox\"/><br /><sub><b>Kevin Fox</b></sub></td>\n <td align=\"center\"><img src=\"https://avatars.githubusercontent.com/u/3022071?v=4\" width=\"100px;\" alt=\"Tom Jakeway\"/><br /><sub><b>Tom Jakeway</b></sub></td>\n <td align=\"center\"><img src=\"https://avatars.githubusercontent.com/u/83293?v=4\" width=\"100px;\" alt=\"Ara Anjargolian\"/><br /><sub><b>Ara Anjargolian</b></sub></td>\n <td align=\"center\"><img src=\"https://avatars.githubusercontent.com/u/15602942?v=4\" width=\"100px;\" alt=\"Hyuckin David Lim\"/><br /><sub><b>Hyuckin David Lim</b></sub></td>\n <td align=\"center\"><img src=\"https://avatars.githubusercontent.com/u/1248116?v=4\" width=\"100px;\" alt=\"James\"/><br /><sub><b>James</b></sub></td>\n </tr>\n</table>\n\n<!-- markdownlint-enable -->\n<!-- prettier-ignore-end -->\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n",
"bugtrack_url": null,
"license": null,
"summary": "a simple tool for making caching functions, methods, and class methods a little bit easier.",
"version": "1.0.7",
"project_urls": {
"Homepage": "https://github.com/ycharts/django_cache_helper"
},
"split_keywords": [
"cache",
" django"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "85a1455ac88d336606c2010bf9e721886d150ee3e152a07d4e50983e1ff44d22",
"md5": "8e218814601f6219822824d6809f0d12",
"sha256": "777ddece6813eafbae644919e335483792b8602dfd1f35ef5f28921d558d32f4"
},
"downloads": -1,
"filename": "django_cache_helper-1.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8e218814601f6219822824d6809f0d12",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 6818,
"upload_time": "2024-05-03T19:42:26",
"upload_time_iso_8601": "2024-05-03T19:42:26.801775Z",
"url": "https://files.pythonhosted.org/packages/85/a1/455ac88d336606c2010bf9e721886d150ee3e152a07d4e50983e1ff44d22/django_cache_helper-1.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "013cd781a47aba792c130866048113a7712b518b8836efdb18785db9e39e88c6",
"md5": "d0ef79b96675dceaf3a60301036a115e",
"sha256": "698681d26321adad73f6aa38c343b770d997a017f01a701682d33da984243b0d"
},
"downloads": -1,
"filename": "django_cache_helper-1.0.7.tar.gz",
"has_sig": false,
"md5_digest": "d0ef79b96675dceaf3a60301036a115e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 6957,
"upload_time": "2024-05-03T19:42:28",
"upload_time_iso_8601": "2024-05-03T19:42:28.527710Z",
"url": "https://files.pythonhosted.org/packages/01/3c/d781a47aba792c130866048113a7712b518b8836efdb18785db9e39e88c6/django_cache_helper-1.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-03 19:42:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ycharts",
"github_project": "django_cache_helper",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "Django",
"specs": [
[
">=",
"4.2"
],
[
"<",
"5.0"
]
]
},
{
"name": "coverage",
"specs": []
},
{
"name": "pre-commit",
"specs": []
},
{
"name": "build",
"specs": []
},
{
"name": "twine",
"specs": []
}
],
"lcname": "django-cache-helper"
}