k3cacheable
Cache data which access frequently.
k3cacheable is a component of pykit3 project: a python3 toolkit set.
Cache data which access frequently.
Install
pip install k3cacheable
Synopsis
import time
import k3cacheable
# create a `LRU`, capacity:10 timeout:60
c = k3cacheable.LRU(10, 60)
# set value like the `dict`
c["key"] = "val"
# get value like the `dict`
# if item timeout, delete it and raise `KeyError`
# if item not exist, raise `KeyError`
try:
val = c["key"]
except KeyError:
print("key error")
cache_data = {
"key1": "val_1",
"key2": "val_2",
}
# define the function with a decorator
@k3cacheable.cache("cache_name", capacity=100, timeout=60, is_deepcopy=False, mutex_update=False)
def get_data(param):
return cache_data.get(param, "")
# call `get_data`, if item has not been cached, cache the return value
data = get_data("key1")
# call `get_data` use the same param, data will be got from cache
time.sleep(1)
data = get_data("key1")
# if item timeout, when call `get_data`, cache again
time.sleep(1)
data = get_data("key1")
# define a method with a decorator
class MethodCache:
@k3cacheable.cache("method_cache_name", capacity=100, timeout=60, is_deepcopy=False, mutex_update=False)
def get_data(self, param):
return cache_data.get(param, "")
mm = MethodCache()
data = mm.get_data("key2")
Author
Zhang Yanpo (张炎泼) drdr.xp@gmail.com
Copyright and License
The MIT License (MIT)
Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com
Metadata
Release files for k3cacheable 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 |
|---|---|---|---|---|
| k3cacheable-0.1.4.tar.gz | 7.3 kB | Without provenance | Details for k3cacheable-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| k3cacheable-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for k3cacheable-0.1.4-py3-none-any.whl |
Total release size: 13.7 kB
Release files / k3cacheable-0.1.4.tar.gz
| Download URL | k3cacheable-0.1.4.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f24ffd35c61431520ec3e225b2073167537a45e6544f86d4603d8cffd3c13d00
|
|
BLAKE2b-256 checksum How to use checksums |
2c2717b86ee228b20b097ef2bd458b64ecece9a4db4f9f502fd81edb165f4ce4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / k3cacheable-0.1.4-py3-none-any.whl
| Download URL | k3cacheable-0.1.4-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c99c7881d7ebb5c695bc49bf1456bea019ba4f7063465c5b8fa6f449dcfec144
|
|
BLAKE2b-256 checksum How to use checksums |
acb2e39b0dc148377316187fa42adc43e53e3f7eb520f162466064884564feee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Security for k3cacheable 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.