Debian Codegraph @

docs/examples/stores/expiry_renew_on_get.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 await sleep(0.5)
11
12 await store.get("foo", renew_for=1) # this will reset the time to live to one second
13
14 await sleep(1)
15 # it has now been 1.5 seconds since the key was set with a life time of one second,
16 # so it should have expired however, since it was renewed for one second, it is still available
17 value = await store.get("foo")
18 print(value)