docs/examples/stores/expiry.py
raw| 1 | from asyncio import sleep |
| 2 | |
| 3 | from litestar.stores.memory import MemoryStore |
| 4 | |
| 5 | store = MemoryStore() |
| 6 | |
| 7 | |
| 8 | async def main() -> None: |
| 9 | await store.set("foo", b"bar", expires_in=1) |
| 10 | value = await store.get("foo") |
| 11 | print(value) |
| 12 | |
| 13 | await sleep(1) |
| 14 | value = await store.get("foo") # this will return 'None', since the key has expired |
| 15 | print(value) |