Mo-Cache
a simple cache lib support memory、file、redis
Github: https://github.com/mouday/mo-cache
install
pip install mo-cache
demo
快速开始
from mo_cache import MemoryCache
cache = MemoryCache()
# 此时的key默认是函数名 foo
@cache
def foo(a, b):
return a + b
if __name__ == '__main__':
foo()
更多示例
1、使用装饰器
# 主动设置key, 过期时间单位:秒s
@cache(key='custom_key', expire=30)
def foo(a, b):
return a + b
2、主动设置和获取
cache.set(key='custom_key', value='value', expire=30)
value = cache.get(key='custom_key')
MemoryCache, FileCache, RedisCache实现了共同的接口(set/get/call),
只是构造参数稍有不同
from mo_cache import MemoryCache, FileCache, RedisCache
memory_cache = MemoryCache()
file_cache = FileCache(cache_dir='cache')
redis_cache = RedisCache(redis_url='redis://localhost:6379/0')
继承体系
class CacheAbstract(object):
"""统一的接口"""
def set(self, key, value, expire=-1):
pass
def get(self, key):
pass
class CacheDecorator(CacheAbstract):
"""cache 装饰器"""
def __call__(self, key=None, expire=-1):
pass
class MemoryCache(CacheDecorator):
"""内存缓存"""
class FileCache(CacheDecorator):
"""文件缓存"""
class RedisCache(CacheDecorator):
"""Redis 缓存"""
Metadata
Release files for mo-cache 0.0.8
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 |
|---|---|---|---|---|
| mo-cache-0.0.8.tar.gz | 4.7 kB | Without provenance | Details for mo-cache-0.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mo_cache-0.0.8-py3-none-any.whl | Python 3 | none | any | Details for mo_cache-0.0.8-py3-none-any.whl |
Total release size: 13.1 kB
Release files / mo-cache-0.0.8.tar.gz
| Download URL | mo-cache-0.0.8.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3fd1561dca04a8f780b50ca55d1d4ea66aa989405872ac7a638b50f98e3e8f87
|
|
BLAKE2b-256 checksum How to use checksums |
b720f9a90499a89827cf892f47e175d57494ed83987ab3c5d242b473d85eeffc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.0
|
Release files / mo_cache-0.0.8-py3-none-any.whl
| Download URL | mo_cache-0.0.8-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
51dececac4db8a51daa38abf9cde951822ee2796ed5d35c422a6f0ce935cd06d
|
|
BLAKE2b-256 checksum How to use checksums |
c3f126689a304c84b631464790d5a87a0da69e4eecfc3c657fb8e5b1ba66aa9a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.0
|
Security for mo-cache 0.0.8
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.