Skip to content

Latest commit

 

History

History
41 lines (25 loc) · 687 Bytes

README.md

File metadata and controls

41 lines (25 loc) · 687 Bytes

Cachepot

The FastAPI cache the way it should be.

Installation

pip install fastapi-cachepot

Usage

import redis.asyncio as redis

from cachepot.app import CachedFastAPI
from cachepot.constants import CachePolicy
from cachepot.storages import RedisStorage

app = CachedFastAPI()

client = redis.from_url('redis://127.0.0.1:6379')
storage = RedisStorage(client)

cache_policy = CachePolicy(
    storage=storage,
    key='cached_hello_world',
    ttl=30,
)


@app.get(path='', cache_policy=cache_policy)
async def cached_hello_world():
    return {'result': 'hello, world!'}