fastapi-cache-0.1.0
توضیحات
FastAPI simple cache
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | fastapi-cache-0.1.0 |
| نام | fastapi-cache |
| نسخه کتابخانه | 0.1.0 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Ivan Sushkov <comeuplater> |
| ایمیل نویسنده | - |
| آدرس صفحه اصلی | https://github.com/comeuplater/fastapi_cache |
| آدرس اینترنتی | https://pypi.org/project/fastapi-cache/ |
| مجوز | MIT License |
# FastAPI Cache
[](https://app.codacy.com/manual/ivan.sushkov/fastapi_cache?utm_source=github.com&utm_medium=referral&utm_content=comeuplater/fastapi_cache&utm_campaign=Badge_Grade_Dashboard)
[](https://opensource.org/licenses/MIT)
[](https://pypi.python.org/pypi/fastapi-cache/)
[](https://pepy.tech/project/fastapi-cache)
[](https://travis-ci.com/comeuplater/fastapi_cache)
Implements simple lightweight cache system as dependencies in FastAPI.
## Installation
```sh
pip install fastapi-cache
```
## Usage example
```python
from fastapi import Depends, FastAPI
from fastapi_cache import caches, close_caches
from fastapi_cache.backends.redis import CACHE_KEY, RedisCacheBackend
app = FastAPI()
def redis_cache():
return caches.get(CACHE_KEY)
@app.get('/')
async def hello(
cache: RedisCacheBackend = Depends(redis_cache)
):
in_cache = await cache.get('some_cached_key')
if not in_cache:
await cache.set('some_cached_key', 'new_value', 5)
return {'response': in_cache or 'default'}
@app.on_event('startup')
async def on_startup() -> None:
rc = RedisCacheBackend('redis://redis')
caches.set(CACHE_KEY, rc)
@app.on_event('shutdown')
async def on_shutdown() -> None:
await close_caches()
```
## TODO
* [X] Add tests
* [ ] ~~Add registry decorator~~
* [ ] Add dependency for requests caching
## Acknowledgments
* [Balburdia](https://github.com/Balburdia)
* [xobtoor](https://github.com/xobtoor)
* [jersobh](https://github.com/jersobh)
## Changelog
* 0.0.6 Added typings for backends. Specific arguments now need to be passed through **kwargs.
Set default encoding to utf-8 for redis backend, removed default TTL for redis keys.
نحوه نصب
نصب پکیج whl fastapi-cache-0.1.0:
pip install fastapi-cache-0.1.0.whl
نصب پکیج tar.gz fastapi-cache-0.1.0:
pip install fastapi-cache-0.1.0.tar.gz