Metadata-Version: 2.1
Name: fastapi-cache
Version: 0.0.2
Summary: FastAPI simple cache
Home-page: https://github.com/comeuplater/fastapi_cache
Author: Ivan Sushkov <comeuplater>
License: MIT License
Description: # 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
        
        * [ ] Add tests
        * [ ] Add registry decorator
Keywords: redis,aioredis,asyncio,fastapi,starlette,cache
Platform: UNKNOWN
Description-Content-Type: text/markdown
