An cache manager implement with `asyncio` backends
1.Install omi_cache_manager from `pip`
$pip install omi_cache_manager
or install from source code
$python setup.py install
2.Install backend for omi_cache_manager, [aioredis](https://github.com/aio-libs/aioredis/) or [aredis](https://github.com/NoneGG/aredis)
$pip install aioredis
$pip install aredis
3.Apply to your project.
# use redis server as cache context manager
cache = AsyncCacheManager(
app, # None if no app context to set
cache_backend="omi_cache_manager.aredis_backend.ARedisBackend",
config={
"CACHE_REDIS_SCHEME": "redis",
"CACHE_REDIS_HOST": "localhost",
"CACHE_REDIS_PORT": 6379,
"CACHE_REDIS_PASSWORD": "",
"CACHE_REDIS_DATABASE": 0,
}
)
# use simple dictionary as cache context manager
cache = AsyncCacheManager(
app, # None if no app context to set
cache_backend="omi_cache_manager.backends.SimpleCacheBackend",
config={
"CACHE_KEY_PREFIX": "MOCK_SIMPLE_INTEGRATION_TEST:"
}
)
4.Test Cache if is work, and enjoy omi_cache_manager
# GET
value = await cache.get("key")
value = await cache.set("key", "val")
value = await cache.add("key", "val")
value = await cache.delete("key")
5.We implemented a demo api provider use [FastAPI](https://github.com/tiangolo/fastapi) to show How to use this library. and testing is included.
@See mock_fastapi.pyfor detail