Name | cachr JSON |
Version |
0.0.9
JSON |
| download |
home_page | None |
Summary | Easy caching in Python. Cachr allows you to compose your own cache and comes pre-packaged with many useful caches |
upload_time | 2024-11-04 13:10:31 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | None |
keywords |
caching
cache
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
|
```text
██████╗ █████╗ ██████╗██╗ ██╗██████╗
██╔════╝██╔══██╗██╔════╝██║ ██║██╔══██╗
██║ ███████║██║ ███████║██████╔╝
██║ ██╔══██║██║ ██╔══██║██╔══██╗
╚██████╗██║ ██║╚██████╗██║ ██║██║ ██║
╚═════╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝
```






# cachr: superfast, composable caching for Python
[//]: # (| | |)
[//]: # (|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|)
[//]: # (| Testing |  |)
[//]: # (| Package | [](https://pypi.org/project/cachr/) [](https://pypistats.org/packages/cachr) <br/>  |)
[//]: # (| Meta |    |)
[//]: # (| Social |   | )
**cachr** is a Python package that provides superfast, composable caches designed to
optimize your applications in an easy and intuitive way.
It aims to be the go-to package to use and build caches that make your applications
superfast, memory-efficient and user-friendly.
```shell
pip install cachr
```
## Table of Contents
- [Main Features](#main-features)
- [Usage Example](#Usage-example)
- [Installation](#Installation)
- [Dependencies](#Dependencies)
- [License](#license)
- [Documentation](#documentation)
- [Development](#development)
- [Contributing to Cachr](#Development)
## Main Features
- 🐍 Pure Python
- 🖌 Easily extendable
- 👨🎨 User-friendly
## Usage Example
At the moment there are five caches available for use:
- LFUCache: Removes the least frequently used item in the cache when it overflows
- LRUCache: A Least Recently Used Cache removes the least recently used item when it overflows
- RandomReplaceCache: randomly expells an item from the cache when it overflows
- TTLCache: A Time-To-Live-cache acts like a LRUCache and also removes an entry from the cache after a certain expiration time
- SlidingWindowCache: Like a TTLCache but it renews the expiration date eacht time an item is requested from the cache.
All caches are added to your code in two ways: by `decorator` or as a regular object.
Decorator:
```python
import time
from cachr import LRUCache
# 1. Decorate your function
@LRUCache(capacity=2)
def add(i, y):
time.sleep(1)
print("adding..")
return i + y
print(add(1, 2)) # <-- takes a second to calculate
print(add(1, 2)) # <-- takes value from cache immediately
print(add(1, 2)) # <-- takes value from cache immediately
```
Object:
```python
from cachr import TTLCache
my_cache = TTLCache(capacity=25, ttl_seconds=60)
def very_expensive_function(number:int) -> int:
return number * number
for i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 3, 5, 7, 9, 1, 1, 1, 1]:
value_from_cache = my_cache.get(i)
if value_from_cache is not None:
print(f"Answer for {i} is {value_from_cache}")
continue
print(f"calculating expensive function for {i}..")
my_cache.put(key=i, value=very_expensive_function(number=i))
```
## Installation
```sh
pip install cachr
```
The source code is currently hosted on GitHub at:
https://github.com/mike-huls/cachr
Binary installers for the latest released version are available at the [Python
Package Index (PyPI)](https://pypi.org/project/cachr).
## Dependencies
Cachr has no Python dependencies
## License
[MIT](LICENSE.txt)
## Documentation
🔨 Under construction
## Development
Find the changelog and list of upcoming features [here](doc/CHANGELOG.md).
<br>
**Contributions** are always welcome; feel free to submit bug reports, bug fixes, feature requests, documentation improvements or enhancements!
<hr>
[Go to Top](#table-of-contents)
Raw data
{
"_id": null,
"home_page": null,
"name": "cachr",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "caching, cache",
"author": null,
"author_email": "Mike Huls <mikehuls42@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/e9/c7/db17bd94de790f37e2de9d7e76628c76753d9c35d798518a8e59cd3527c3/cachr-0.0.9.tar.gz",
"platform": null,
"description": " ```text\n \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \n\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255d\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255d\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557 \n\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255d \n\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557 \n\u255a\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u255a\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \n \u255a\u2550\u2550\u2550\u2550\u2550\u255d\u255a\u2550\u255d \u255a\u2550\u255d \u255a\u2550\u2550\u2550\u2550\u2550\u255d\u255a\u2550\u255d \u255a\u2550\u255d\u255a\u2550\u255d \u255a\u2550\u255d \n```\n\n\n\n\n\n\n\n# cachr: superfast, composable caching for Python\n\n[//]: # (| | |)\n\n[//]: # (|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|)\n\n[//]: # (| Testing |  |)\n\n[//]: # (| Package | [](https://pypi.org/project/cachr/) [](https://pypistats.org/packages/cachr) <br/>  |)\n\n[//]: # (| Meta |    |)\n\n[//]: # (| Social |   | )\n\n**cachr** is a Python package that provides superfast, composable caches designed to \noptimize your applications in an easy and intuitive way.\nIt aims to be the go-to package to use and build caches that make your applications \nsuperfast, memory-efficient and user-friendly.\n```shell\npip install cachr\n```\n\n## Table of Contents\n- [Main Features](#main-features)\n- [Usage Example](#Usage-example)\n- [Installation](#Installation)\n- [Dependencies](#Dependencies)\n- [License](#license)\n- [Documentation](#documentation)\n- [Development](#development)\n- [Contributing to Cachr](#Development)\n\n## Main Features\n- \ud83d\udc0d Pure Python\n- \ud83d\udd8c Easily extendable\n- \ud83d\udc68\u200d\ud83c\udfa8 User-friendly\n\n## Usage Example\nAt the moment there are five caches available for use: \n- LFUCache: Removes the least frequently used item in the cache when it overflows\n- LRUCache: A Least Recently Used Cache removes the least recently used item when it overflows\n- RandomReplaceCache: randomly expells an item from the cache when it overflows\n- TTLCache: A Time-To-Live-cache acts like a LRUCache and also removes an entry from the cache after a certain expiration time\n- SlidingWindowCache: Like a TTLCache but it renews the expiration date eacht time an item is requested from the cache.\n\nAll caches are added to your code in two ways: by `decorator` or as a regular object.\nDecorator:\n```python\nimport time\nfrom cachr import LRUCache\n\n\n# 1. Decorate your function\n@LRUCache(capacity=2)\ndef add(i, y):\n time.sleep(1)\n print(\"adding..\")\n return i + y\n\n\nprint(add(1, 2)) # <-- takes a second to calculate\nprint(add(1, 2)) # <-- takes value from cache immediately \nprint(add(1, 2)) # <-- takes value from cache immediately \n```\n\nObject:\n```python\nfrom cachr import TTLCache\n\nmy_cache = TTLCache(capacity=25, ttl_seconds=60)\n\ndef very_expensive_function(number:int) -> int:\n return number * number\n\nfor i in [1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 3, 5, 7, 9, 1, 1, 1, 1]:\n value_from_cache = my_cache.get(i)\n if value_from_cache is not None:\n print(f\"Answer for {i} is {value_from_cache}\")\n continue\n print(f\"calculating expensive function for {i}..\")\n my_cache.put(key=i, value=very_expensive_function(number=i))\n```\n\n\n\n## Installation\n```sh\npip install cachr\n```\nThe source code is currently hosted on GitHub at:\nhttps://github.com/mike-huls/cachr\n\nBinary installers for the latest released version are available at the [Python\nPackage Index (PyPI)](https://pypi.org/project/cachr).\n\n## Dependencies\nCachr has no Python dependencies\n\n## License\n[MIT](LICENSE.txt)\n\n## Documentation\n\ud83d\udd28 Under construction\n\n## Development\nFind the changelog and list of upcoming features [here](doc/CHANGELOG.md).\n<br>\n**Contributions** are always welcome; feel free to submit bug reports, bug fixes, feature requests, documentation improvements or enhancements!\n\n<hr>\n\n[Go to Top](#table-of-contents)\n",
"bugtrack_url": null,
"license": null,
"summary": "Easy caching in Python. Cachr allows you to compose your own cache and comes pre-packaged with many useful caches",
"version": "0.0.9",
"project_urls": {
"Bug Tracker": "https://github.com/mike-huls/cachr/issues",
"Changelog": "https://github.com/mike-huls/cachr/blob/master/CHANGELOG.md/",
"Documentation": "https://github.com/mike-huls/cachr/blob/master/README.md/",
"Homepage": "https://github.com/mike-huls/cachr",
"Say Thanks!": "https://www.buymeacoffee.com/mikehuls",
"Source": "https://github.com/mike-huls/cachr/"
},
"split_keywords": [
"caching",
" cache"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "0b57909ef2f75016266b56548bea92eb94b28f0263a2a8026714502e98a91acc",
"md5": "314ab9cc2faf2683422054e50c79e372",
"sha256": "e646613a7a005363f4a2d30026fcb8988fd8f0ed0464b2a0bbaafee4ccd6df22"
},
"downloads": -1,
"filename": "cachr-0.0.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "314ab9cc2faf2683422054e50c79e372",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 9936,
"upload_time": "2024-11-04T13:10:29",
"upload_time_iso_8601": "2024-11-04T13:10:29.816426Z",
"url": "https://files.pythonhosted.org/packages/0b/57/909ef2f75016266b56548bea92eb94b28f0263a2a8026714502e98a91acc/cachr-0.0.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "e9c7db17bd94de790f37e2de9d7e76628c76753d9c35d798518a8e59cd3527c3",
"md5": "ec181971244b02fd4c67586f8fac58ee",
"sha256": "e2896ab8c10a703a8fb6d2ea41b46ec57d8a6421ca5ee2e6e8bb8ae69f0297a5"
},
"downloads": -1,
"filename": "cachr-0.0.9.tar.gz",
"has_sig": false,
"md5_digest": "ec181971244b02fd4c67586f8fac58ee",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 13322,
"upload_time": "2024-11-04T13:10:31",
"upload_time_iso_8601": "2024-11-04T13:10:31.338716Z",
"url": "https://files.pythonhosted.org/packages/e9/c7/db17bd94de790f37e2de9d7e76628c76753d9c35d798518a8e59cd3527c3/cachr-0.0.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-04 13:10:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mike-huls",
"github_project": "cachr",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "cachr"
}