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
}
}
}
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 | |
|---|---|---|---|
| xcache-lib-0.0.2.tar.gz | 2.8 kB | Details |
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
|