sag-py-cache-decorator


Namesag-py-cache-decorator JSON
Version 0.1.1 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-02-15 09:37:56
maintainer
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


[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": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "cache,decorator",
    "author": "Samhammer AG",
    "author_email": "support@samhammer.de",
    "download_url": "https://files.pythonhosted.org/packages/4b/64/4927702ccd6ac2461d8a02a34f221015e7491e513375bf5e9a0ab28f121f/sag-py-cache-decorator-0.1.1.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\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.1",
    "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": "511abf2173cd355bc52856c771150f56bd607ae5f3699d75f875b7b24e785b64",
                "md5": "9511c1bf0560dd9fa7ab90820cbd3055",
                "sha256": "9b6a9cbf1b863922d6d61baf2a5306637d8f08d6ebff16d28d9e8a04b24a4a53"
            },
            "downloads": -1,
            "filename": "sag_py_cache_decorator-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9511c1bf0560dd9fa7ab90820cbd3055",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 6446,
            "upload_time": "2024-02-15T09:37:55",
            "upload_time_iso_8601": "2024-02-15T09:37:55.126839Z",
            "url": "https://files.pythonhosted.org/packages/51/1a/bf2173cd355bc52856c771150f56bd607ae5f3699d75f875b7b24e785b64/sag_py_cache_decorator-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4b644927702ccd6ac2461d8a02a34f221015e7491e513375bf5e9a0ab28f121f",
                "md5": "0caae81d5d05be21f556a9ce8629a20d",
                "sha256": "29994e27e08fd10d792269f0e7cc532e2f5ccc69f8d2374f16e610bec36a7dba"
            },
            "downloads": -1,
            "filename": "sag-py-cache-decorator-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "0caae81d5d05be21f556a9ce8629a20d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 7234,
            "upload_time": "2024-02-15T09:37:56",
            "upload_time_iso_8601": "2024-02-15T09:37:56.341200Z",
            "url": "https://files.pythonhosted.org/packages/4b/64/4927702ccd6ac2461d8a02a34f221015e7491e513375bf5e9a0ab28f121f/sag-py-cache-decorator-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-15 09:37:56",
    "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.18929s