From fb7552bfcfa6df92201f90246a2e856b7da507e1 Mon Sep 17 00:00:00 2001 From: Christophe Bornet Date: Tue, 13 Feb 2024 04:02:38 +0100 Subject: [PATCH] Add async methods to InMemoryCache (#17425) Add async methods to InMemoryCache --- libs/community/langchain_community/cache.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libs/community/langchain_community/cache.py b/libs/community/langchain_community/cache.py index 54996071f8655..4719d661ba104 100644 --- a/libs/community/langchain_community/cache.py +++ b/libs/community/langchain_community/cache.py @@ -192,6 +192,20 @@ def clear(self, **kwargs: Any) -> None: """Clear cache.""" self._cache = {} + async def alookup(self, prompt: str, llm_string: str) -> Optional[RETURN_VAL_TYPE]: + """Look up based on prompt and llm_string.""" + return self.lookup(prompt, llm_string) + + async def aupdate( + self, prompt: str, llm_string: str, return_val: RETURN_VAL_TYPE + ) -> None: + """Update cache based on prompt and llm_string.""" + self.update(prompt, llm_string, return_val) + + async def aclear(self, **kwargs: Any) -> None: + """Clear cache.""" + self.clear() + Base = declarative_base()