Setup normal class to mobio lru cache
Project description
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_cache = LruCache(store_type=__store_type, config_file_name=__file_config)
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
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
m-caching-0.1.2.tar.gz
(5.9 kB
view hashes)
Built Distribution
Close
Hashes for m_caching-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6cd4110baab572edc7b80e824314880f9c6868420f51463846433e87b8167c4 |
|
MD5 | 378bbbe9a919dc97b1158f9808dbf432 |
|
BLAKE2b-256 | 0e62d77edba88bed0d9f078bd6af9432d2dd17920e781df91a64245baa9f0b71 |