XCache: A simplest and thread-safe LRU cache, which support key-func, release-func and hit-stat.
Setup
pip install xcache-lib
Key Features
- LRU cache
- Thread safe
- Support special key function
- Support special release function
- Has detail hit stat
Core Function Descriptor: xcache
@xcache(cache_size, key_func=None, release_func=None, log_keys=False)
| Param Value | Description |
|---|---|
| cache_size | size of cache storage |
| key_fun | special key function |
| release_func | special release function |
| log_keys | log keys, for DEBUG |
Quick Start
from xcache import xcache, show_xcache_hit_stat
@xcache(3, key_func=lambda x,y: x, log_keys=True)
def calc(x, y):
print("calc {}, {}".format(x, y))
return x + y
if __name__ == "__main__":
print(calc(5, 6))
print(calc(5, 6))
print(calc(5, 6))
print(calc(5, 5))
print(calc(4, 6))
print(calc(3, 6))
print(calc(2, 6))
print(calc(1, 6))
print(calc(9, 6))
print(json.dumps(show_xcache_hit_stat(x), indent=4)) # show detail hit stat
outputs:
calc 5, 6
11
11
11
calc 5, 5
10
calc 4, 6
10
calc 3, 6
9
calc 2, 6
8
calc 1, 6
7
calc 9, 6
15
{
"hit_rate": 22.22222222222222,
"dup_calc_rate": 0.6666666666666666,
"hit": [
2,
7
],
"keys_num": 1,
"detail": {
"key_detail": {
"1": 6,
"3": 1
},
"hit_detail": {
"2": 1
}
}
}
Metadata
Release files for xcache-lib 0.0.2
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 |
|---|---|---|---|---|
| xcache-lib-0.0.2.tar.gz | 2.8 kB | Without provenance | Details for xcache-lib-0.0.2.tar.gz |
Release files / xcache-lib-0.0.2.tar.gz
| Download URL | xcache-lib-0.0.2.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dbf1e3eb659a5876b03e05c062a8443a0241040509b7d008988d10a29261f7d1
|
|
BLAKE2b-256 checksum How to use checksums |
5babce001cd5fd4de1ec5a2c0fb88e013df6f284b3405c22a1236bed3b5cdbff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.7.3
|
Security for xcache-lib 0.0.2
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.