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: Allow to cache functions for different event loops

Clémence Lesné156faefe1f67
diff --git a/app/helpers/cache.py b/app/helpers/cache.py
index 94bb1ed..93a26c9 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 Awaitable
@@ -15,8 +16,12 @@ def async_lru_cache(maxsize: int = 128):
@functools.wraps(func)
async def wrapper(*args, **kwargs) -> Awaitable:
- # Create a cache key from args and kwargs, using frozenset for kwargs to ensure hashability
- key = (args, frozenset(kwargs.items()))
+ # Create a cache key from event loop, args and kwargs, using frozenset for kwargs to ensure hashability
+ key = (
+ asyncio.get_event_loop(),
+ args,
+ frozenset(kwargs.items()),
+ )
if key in cache:
# Move the recently accessed key to the end (most recently used)