sag-py-cache-decorator


Namesag-py-cache-decorator JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/SamhammerAG/sag_py_cache_decorator
SummaryA decorator to cache method call results with similar parameters
upload_time2024-05-06 10:40:46
maintainerNone
docs_urlNone
authorSamhammer AG
requires_python>=3.8
licenseMIT
keywords cache decorator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # sag_py_cache_decorator
[![Maintainability][codeclimate-image]][codeclimate-url]
[![Coverage Status][coveralls-image]][coveralls-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]

A cache annotation that can be used to cache calls to a method

## What it does
- Caches calls to methods if the same parameters are used
- Removes the least recently used cache item if a optional maximum is reached
- Supports sync and async functions
- Possibility to skip the cache by parameter
- Possibility to clear the cache entirely or for one set of parameters

### Installation
pip install sag-py-cache-decorator

## How to use
```python
from sag_py_cache_decorator.lru_cache import lru_cache

@lru_cache(maxsize=3)
def my_function(str: str, str2: str) -> str:
    return f"{str}-{str2}"
```

This is the regular use case of the cache.

Available decorator arguments:

| Argument | Description                                                                                                                | Default |
|----------|----------------------------------------------------------------------------------------------------------------------------|---------|
| maxsize  | If this size is reached, the least recently used cache item will be removed. Can be set to None to have a unlimited cache. | 128     |

```python
from sag_py_cache_decorator.lru_cache import lru_cache

@lru_cache(maxsize=3)
def my_function(
    str: str,
    lru_clear_cache: bool = False,
) -> str:
    return f"{str}-{str2}"

my_function("one")
my_function("two")
# Before executing the next function the cache is cleared and then
# rebuilt with the results of three and four because of lru_clear_cache = True
my_function("three", lru_clear_cache = True)
my_function("four")
```
Available function arguments:
| Argument            | Description                                                                                                                           | Default |
|---------------------|---------------------------------------------------------------------------------------------------------------------------------------|---------|
| lru_use_cache       | If set to false, the function call skips the cache. Existing cached items are ignored and new ones are not written for that call.     | True    |
| lru_clear_cache     | If set to true, the cache is cleared entirely before executing the method. The result of the call is then cached again.               | False   |
| lru_clear_arg_cache | If set to true, the result for this set of parameters is removed from cache(if present). The result of the call is then cached again. | False   |

## How to start developing

### With vscode

Just install vscode with dev containers extension. All required extensions and configurations are prepared automatically.

### With pycharm

* Install latest pycharm
* Install pycharm plugin BlackConnect
* Install pycharm plugin Mypy
* Configure the python interpreter/venv
* pip install requirements-dev.txt
* pip install black[d]
* Ctl+Alt+S => Check Tools => BlackConnect => Trigger when saving changed files
* Ctl+Alt+S => Check Tools => BlackConnect => Trigger on code reformat
* Ctl+Alt+S => Click Tools => BlackConnect => "Load from pyproject.yaml" (ensure line length is 120)
* Ctl+Alt+S => Click Tools => BlackConnect => Configure path to the blackd.exe at the "local instance" config (e.g. C:\Python310\Scripts\blackd.exe)
* Ctl+Alt+S => Click Tools => Actions on save => Reformat code
* Restart pycharm

## How to publish
* Update the version in setup.py and commit your change
* Create a tag with the same version number
* Let github do the rest

## How to test

To avoid publishing to pypi unnecessarily you can do as follows

* Tag your branch however you like
* Use the chosen tag in the requirements.txt-file of the project you want to test this library in, eg. `sag_py_cache_decorator==<your tag>`
* Rebuild/redeploy your project

[codeclimate-image]:https://api.codeclimate.com/v1/badges/e29dcd8f76877962c93b/maintainability
[codeclimate-url]:https://codeclimate.com/github/SamhammerAG/sag_py_cache_decorator/maintainability
[coveralls-image]:https://coveralls.io/repos/github/SamhammerAG/sag_py_cache_decorator/badge.svg?branch=master
[coveralls-url]:https://coveralls.io/github/SamhammerAG/sag_py_cache_decorator?branch=master
[snyk-image]:https://snyk.io/test/github/SamhammerAG/sag_py_cache_decorator/badge.svg
[snyk-url]:https://snyk.io/test/github/SamhammerAG/sag_py_cache_decorator

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/SamhammerAG/sag_py_cache_decorator",
    "name": "sag-py-cache-decorator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "cache, decorator",
    "author": "Samhammer AG",
    "author_email": "support@samhammer.de",
    "download_url": "https://files.pythonhosted.org/packages/39/1d/abef1fce29574eca23fc54cf4a4f8367a35ded3aff798e2faeb407eee652/sag_py_cache_decorator-0.1.2.tar.gz",
    "platform": null,
    "description": "# sag_py_cache_decorator\n[![Maintainability][codeclimate-image]][codeclimate-url]\n[![Coverage Status][coveralls-image]][coveralls-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n\nA cache annotation that can be used to cache calls to a method\n\n## What it does\n- Caches calls to methods if the same parameters are used\n- Removes the least recently used cache item if a optional maximum is reached\n- Supports sync and async functions\n- Possibility to skip the cache by parameter\n- Possibility to clear the cache entirely or for one set of parameters\n\n### Installation\npip install sag-py-cache-decorator\n\n## How to use\n```python\nfrom sag_py_cache_decorator.lru_cache import lru_cache\n\n@lru_cache(maxsize=3)\ndef my_function(str: str, str2: str) -> str:\n    return f\"{str}-{str2}\"\n```\n\nThis is the regular use case of the cache.\n\nAvailable decorator arguments:\n\n| Argument | Description                                                                                                                | Default |\n|----------|----------------------------------------------------------------------------------------------------------------------------|---------|\n| maxsize  | If this size is reached, the least recently used cache item will be removed. Can be set to None to have a unlimited cache. | 128     |\n\n```python\nfrom sag_py_cache_decorator.lru_cache import lru_cache\n\n@lru_cache(maxsize=3)\ndef my_function(\n    str: str,\n    lru_clear_cache: bool = False,\n) -> str:\n    return f\"{str}-{str2}\"\n\nmy_function(\"one\")\nmy_function(\"two\")\n# Before executing the next function the cache is cleared and then\n# rebuilt with the results of three and four because of lru_clear_cache = True\nmy_function(\"three\", lru_clear_cache = True)\nmy_function(\"four\")\n```\nAvailable function arguments:\n| Argument            | Description                                                                                                                           | Default |\n|---------------------|---------------------------------------------------------------------------------------------------------------------------------------|---------|\n| lru_use_cache       | If set to false, the function call skips the cache. Existing cached items are ignored and new ones are not written for that call.     | True    |\n| lru_clear_cache     | If set to true, the cache is cleared entirely before executing the method. The result of the call is then cached again.               | False   |\n| lru_clear_arg_cache | If set to true, the result for this set of parameters is removed from cache(if present). The result of the call is then cached again. | False   |\n\n## How to start developing\n\n### With vscode\n\nJust install vscode with dev containers extension. All required extensions and configurations are prepared automatically.\n\n### With pycharm\n\n* Install latest pycharm\n* Install pycharm plugin BlackConnect\n* Install pycharm plugin Mypy\n* Configure the python interpreter/venv\n* pip install requirements-dev.txt\n* pip install black[d]\n* Ctl+Alt+S => Check Tools => BlackConnect => Trigger when saving changed files\n* Ctl+Alt+S => Check Tools => BlackConnect => Trigger on code reformat\n* Ctl+Alt+S => Click Tools => BlackConnect => \"Load from pyproject.yaml\" (ensure line length is 120)\n* Ctl+Alt+S => Click Tools => BlackConnect => Configure path to the blackd.exe at the \"local instance\" config (e.g. C:\\Python310\\Scripts\\blackd.exe)\n* Ctl+Alt+S => Click Tools => Actions on save => Reformat code\n* Restart pycharm\n\n## How to publish\n* Update the version in setup.py and commit your change\n* Create a tag with the same version number\n* Let github do the rest\n\n## How to test\n\nTo avoid publishing to pypi unnecessarily you can do as follows\n\n* Tag your branch however you like\n* Use the chosen tag in the requirements.txt-file of the project you want to test this library in, eg. `sag_py_cache_decorator==<your tag>`\n* Rebuild/redeploy your project\n\n[codeclimate-image]:https://api.codeclimate.com/v1/badges/e29dcd8f76877962c93b/maintainability\n[codeclimate-url]:https://codeclimate.com/github/SamhammerAG/sag_py_cache_decorator/maintainability\n[coveralls-image]:https://coveralls.io/repos/github/SamhammerAG/sag_py_cache_decorator/badge.svg?branch=master\n[coveralls-url]:https://coveralls.io/github/SamhammerAG/sag_py_cache_decorator?branch=master\n[snyk-image]:https://snyk.io/test/github/SamhammerAG/sag_py_cache_decorator/badge.svg\n[snyk-url]:https://snyk.io/test/github/SamhammerAG/sag_py_cache_decorator\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A decorator to cache method call results with similar parameters",
    "version": "0.1.2",
    "project_urls": {
        "Bug Reports": "https://github.com/SamhammerAG/sag_py_cache_decorator/issues",
        "Documentation": "https://github.com/SamhammerAG/sag_py_cache_decorator",
        "Homepage": "https://github.com/SamhammerAG/sag_py_cache_decorator",
        "Source": "https://github.com/SamhammerAG/sag_py_cache_decorator"
    },
    "split_keywords": [
        "cache",
        " decorator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2f21a4c0d38497ecaa0b324127589d98dc706d26efc113946250d0391d635869",
                "md5": "e87d4b17815872cb0677a667b7736bad",
                "sha256": "0bef335467031c67846c86493e2091a8f24a94b31a8f2d5860bcbc1bae3092a4"
            },
            "downloads": -1,
            "filename": "sag_py_cache_decorator-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e87d4b17815872cb0677a667b7736bad",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 6593,
            "upload_time": "2024-05-06T10:40:43",
            "upload_time_iso_8601": "2024-05-06T10:40:43.075622Z",
            "url": "https://files.pythonhosted.org/packages/2f/21/a4c0d38497ecaa0b324127589d98dc706d26efc113946250d0391d635869/sag_py_cache_decorator-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "391dabef1fce29574eca23fc54cf4a4f8367a35ded3aff798e2faeb407eee652",
                "md5": "62d2a092d2f221a219ac3549295eee26",
                "sha256": "9297755e49b7677a789dcaab63b9ed85920f685617b81cf42b2cdd2781907816"
            },
            "downloads": -1,
            "filename": "sag_py_cache_decorator-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "62d2a092d2f221a219ac3549295eee26",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 7557,
            "upload_time": "2024-05-06T10:40:46",
            "upload_time_iso_8601": "2024-05-06T10:40:46.167152Z",
            "url": "https://files.pythonhosted.org/packages/39/1d/abef1fce29574eca23fc54cf4a4f8367a35ded3aff798e2faeb407eee652/sag_py_cache_decorator-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-06 10:40:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "SamhammerAG",
    "github_project": "sag_py_cache_decorator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "sag-py-cache-decorator"
}
        
Elapsed time: 0.25865s