LRU Cache
Thư viện caching của MOBIO. Hỗ trợ cache trên memory hoặc Redis.
Cài đặt:
pip3 install m-caching
Sử dụng:
__store_type = StoreType.REDIS # for redis cache
__store_type = StoreType.LOCAL # for memory cache
__file_config = 'config-file-path'
lru_redis_cache = LruCache(store_type=__store_type, config_file_name=__file_config,
redis_uri='redis://redis:6379/0',
redis_cluster_uri='redis://redis-cluster.redis.svc.cluster.local:6379/0',
redis_type=RedisType.REPLICA)
Ignore empty values from cache
__store_type = StoreType.REDIS
__file_config = 'config-file-path'
lru_cache = LruCache(store_type=__store_type, config_file_name=__file_config)
lru_cache.accept_none(False) # => ignore none values
Usage
cache for class's function
class TestCache:
@lru_cache.add_for_class()
def test(self, x):
print("TestCache::test param %s" % x)
return x + 1
@staticmethod
@lru_cache.add()
def test_static(x):
print("TestCache::test_static test param %s" % x)
return x + 1
@staticmethod
@lru_cache.add_async()
async def test_static_async(x):
print("TestCache::test_static test param %s" % x)
return x + 1
@lru_cache.add_for_class_async()
async def test_async(self, x):
print("TestCache::test param %s" % x)
return x + 1
cache for normal function
@lru_cache.add()
def some_expensive_method(x):
print("Calling some_expensive_method(" + str(x) + ")")
return x + 200
Example config
[REDIS]
host=redis-server
port=6379
cache_prefix=test_cache
Changedlog:
v0.1.14:
- Support Function Async
v0.1.13:
- Support RedisCluster
v0.1.12:
- Fix bug: missing import;
v0.1.11:
- Support python3.9
v0.1.10:
- Sửa lại tên version 0.1.9
v0.1.9:
- Thêm try...except: khi set item vao redis.
Metadata
Release files for m-caching 0.1.15
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 | |
|---|---|---|---|---|
| m-caching-0.1.15.tar.gz | 7.4 kB | Without provenance | Details |
Release files / m-caching-0.1.15.tar.gz
| Download URL | m-caching-0.1.15.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
06496bd9718b973352822905b0f9230e4a58842f70914b0cdba53cd6aedccfe3
|
|
BLAKE2b-256 checksum How to use checksums |
378de01f0cdd953cdc7b8d60d24ed051e14d61ce5a41aa7d065192bfd46b5455
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.7
|
Security for m-caching 0.1.15
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.