From d5623cb7136777933f6a38bbc6a920b704286494 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Sun, 17 Sep 2023 19:35:25 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(manager.py):=20fix=20typo=20?= =?UTF-8?q?in=20comment,=20change=20"ached"=20to=20"cached"=20for=20better?= =?UTF-8?q?=20readability=20=E2=9C=A8=20feat(manager.py):=20add=20error=20?= =?UTF-8?q?handling=20for=20non-picklable=20values=20in=20RedisCache's=20s?= =?UTF-8?q?et=20method=20to=20prevent=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/services/cache/manager.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/backend/langflow/services/cache/manager.py b/src/backend/langflow/services/cache/manager.py index 843eb182e..fc4a590fb 100644 --- a/src/backend/langflow/services/cache/manager.py +++ b/src/backend/langflow/services/cache/manager.py @@ -119,7 +119,8 @@ class InMemoryCache(BaseCacheService, Service): def get_or_set(self, key, value): """ - Retrieve an item from the cache. If the item does not exist, set it with the provided value. + Retrieve an item from the cache. If the item does not exist, + set it with the provided value. Args: key: The key of the item. @@ -207,13 +208,15 @@ class RedisCache(BaseCacheService, Service): host (str, optional): Redis host. port (int, optional): Redis port. db (int, optional): Redis DB. - expiration_time (int, optional): Time in seconds after which a cached item expires. Default is 1 hour. + expiration_time (int, optional): Time in seconds after which a + ached item expires. Default is 1 hour. """ try: import redis except ImportError as exc: raise ImportError( - "RedisCache requires the redis-py package. Please install Langflow with the deploy extra: pip install langflow[deploy]" + "RedisCache requires the redis-py package." + " Please install Langflow with the deploy extra: pip install langflow[deploy]" ) from exc self._client = redis.StrictRedis(host=host, port=port, db=db) @@ -253,7 +256,12 @@ class RedisCache(BaseCacheService, Service): key: The key of the item. value: The value to cache. """ - self._client.setex(key, self.expiration_time, pickle.dumps(value)) + try: + self._client.setex(key, self.expiration_time, pickle.dumps(value)) + except TypeError as exc: + raise TypeError( + "RedisCache only accepts values that can be pickled. " + ) from exc def upsert(self, key, value): """