acache: async cache
A implementation of lru_cache and ttl_cache for asyncio.
Install
# from pip
pip3 install --user python-acache
# from github
pip3 install git+https://github.com/Dimfred/acache.git
Alternatives
The difference in my package is that if you call a function with the same args, from different threads the second one will not return a value until the first one is completed, s.t. the value gets definitely cached. Additionally, I allow overwriting the key generation function, so you can pick your own. Also my naming is different, and maybe more pythonic (whatever).
Usage
from acache import alru_cache, attl_cache
# basic lru
@alru_cache(maxsize=2)
async def i_am_cached(foo):
return foo
# use with custom key function
@alru_cache(maxsize=2, make_key=lambda x: type(x))
async def i_cache_based_on_the_input_type(foo)
return foo
class A:
pass
res1 = await i_cache_based_on_the_input_type(A())
res2 = await i_cache_based_on_the_input_type(A())
assert id(res1) == id(res2) # TRUE
# time cache
@attl_cache(seconds=1)
async def cached_for_1_s(bar):
return bar
res1 = await cached_for_1_s(1)
res2 = await cached_for_1_s(2)
assert res1 == res2
# wait 1 second
res3 = await cached_for_1_s(3)
assert res1 != res3
# key function also applies to the attl_cache
Synopsis
def alru_cache(maxsize: int = 128, make_key=None):
...
def attl_cache(
weeks=0,
days=0,
hours=0,
minutes=0,
seconds=0,
milliseconds=0,
microseconds=0,
maxsize=128,
make_key=None,
):
...
Metadata
Release files for python-acache 0.1.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 |
|---|---|---|---|---|
| python-acache-0.1.4.tar.gz | 3.1 kB | Without provenance | Details for python-acache-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_acache-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for python_acache-0.1.4-py3-none-any.whl |
Total release size: 6.9 kB
Release files / python-acache-0.1.4.tar.gz
| Download URL | python-acache-0.1.4.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
409860bd335b8ce357fe4ff5788f78c776e467984f840c04c8bad4c7e3751b5b
|
|
BLAKE2b-256 checksum How to use checksums |
31823f548440da0efe816cc927eed87183c4c318ca150b1726bfb4b04ce9da09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.10.7 Linux/5.19.8-arch1-1
|
Release files / python_acache-0.1.4-py3-none-any.whl
| Download URL | python_acache-0.1.4-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7590a26a012e78baf4832cbf4309a775e2abf6107e11493d78fe1e44ab70bbf
|
|
BLAKE2b-256 checksum How to use checksums |
17255ca8605d8a3a5a99cf6734ed979a343de7e4ca1469219ae48f2bc3779b9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.10.7 Linux/5.19.8-arch1-1
|
Security for python-acache 0.1.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.