| 1 |
import asyncio |
| 2 |
|
| 3 |
from litestar import Litestar, get |
| 4 |
from litestar.config.response_cache import ResponseCacheConfig |
| 5 |
from litestar.stores.redis import RedisStore |
| 6 |
|
| 7 |
|
| 8 |
@get(cache=10) |
| 9 |
async def something() -> str: |
| 10 |
await asyncio.sleep(1) |
| 11 |
return "something" |
| 12 |
|
| 13 |
|
| 14 |
redis_store = RedisStore.with_client(url="redis://localhost/", port=6379, db=0) |
| 15 |
cache_config = ResponseCacheConfig(store="redis_backed_store") |
| 16 |
app = Litestar( |
| 17 |
[something], |
| 18 |
stores={"redis_backed_store": redis_store}, |
| 19 |
response_cache_config=cache_config, |
| 20 |
) |