From dae1bf2ca733d0671c748cd86fc15628a0e8653f Mon Sep 17 00:00:00 2001 From: NeonKirill Date: Mon, 23 Oct 2023 22:13:56 +0200 Subject: [PATCH] Fixed issue with caching --- chat_server/server_utils/cache_utils.py | 1 + chat_server/sio.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/chat_server/server_utils/cache_utils.py b/chat_server/server_utils/cache_utils.py index 75121adc..7acff20d 100644 --- a/chat_server/server_utils/cache_utils.py +++ b/chat_server/server_utils/cache_utils.py @@ -45,6 +45,7 @@ def get(cls, name: str, cache_type: Type = None, **kwargs): """ if not cls.__active_caches.get(name): if cache_type: + kwargs.setdefault("maxsize", 124) cls.__active_caches[name] = cache_type(**kwargs) else: raise KeyError(f"Missing cache instance under {name}") diff --git a/chat_server/sio.py b/chat_server/sio.py index 2f23be70..bff5d11f 100644 --- a/chat_server/sio.py +++ b/chat_server/sio.py @@ -458,9 +458,9 @@ async def request_translate(sid, data): "sid": sid, "input_type": input_type, } - CacheFactory.get("translation_cache", cache_type=LRUCache).put( - key=request_id, value=caching_instance - ) + CacheFactory.get("translation_cache", cache_type=LRUCache)[ + request_id + ] = caching_instance await sio.emit( "request_neon_translations", data={"request_id": request_id, "data": missing_translations},