sag_py_cache_decorator
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
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 |
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 Mypy
- Configure the python interpreter/venv
- pip install requirements-dev.txt
- 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
Metadata
Release files for sag-py-cache-decorator 0.3.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sag_py_cache_decorator-0.3.4.tar.gz | 7.8 kB | Without provenance | Details for sag_py_cache_decorator-0.3.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sag_py_cache_decorator-0.3.4-py3-none-any.whl | Python 3 | none | any | Details for sag_py_cache_decorator-0.3.4-py3-none-any.whl |
Total release size: 14.5 kB
Release files / sag_py_cache_decorator-0.3.4.tar.gz
| Download URL | sag_py_cache_decorator-0.3.4.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8aa752f01ddb4da35d4b7be60b9a042c116295a2b98a2f715de9ab6aad87a9b3
|
|
BLAKE2b-256 checksum How to use checksums |
e150c374e60c99dc9d35a6d54b128fb680d53f33497fafeda0fc9e74d7d947c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / sag_py_cache_decorator-0.3.4-py3-none-any.whl
| Download URL | sag_py_cache_decorator-0.3.4-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5928d1cdd3e7d71bf7735f80ccdbcdc312fa5b0bba79d4b61ba499f9a8596429
|
|
BLAKE2b-256 checksum How to use checksums |
e331bbb2130ee7ca956f1573cf792e4f600ffcc193a3e6a720c9511e623e661e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for sag-py-cache-decorator 0.3.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.