Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

fix: Async cache by asyncio loop

Clémence Lesné078c21c05206
diff --git a/app/helpers/cache.py b/app/helpers/cache.py
index e9443b1..fb6a782 100644
--- a/app/helpers/cache.py
+++ b/app/helpers/cache.py
@@ -1,3 +1,4 @@
+import asyncio
import functools
from collections import OrderedDict
from collections.abc import AsyncGenerator, Awaitable
@@ -32,7 +33,11 @@ def async_lru_cache(maxsize: int = 128):
@functools.wraps(func)
async def wrapper(*args, **kwargs) -> Awaitable:
# Create a cache key from event loop, args and kwargs, using frozenset for kwargs to ensure hashability
- key = (args, frozenset(kwargs.items()))
+ key = (
+ id(asyncio.get_event_loop()),
+ args,
+ frozenset(kwargs.items()),
+ )
if key in cache:
# Move the recently accessed key to the end (most recently used)