diff --git a/libs/checkpoint/langgraph/cache/base/__init__.py b/libs/checkpoint/langgraph/cache/base/__init__.py index 9c8653d23..0dd5aca8e 100644 --- a/libs/checkpoint/langgraph/cache/base/__init__.py +++ b/libs/checkpoint/langgraph/cache/base/__init__.py @@ -21,22 +21,22 @@ class BaseCache(ABC, Generic[T]): def get(self, keys: Sequence[str]) -> dict[str, T]: """Get the cached values for the given keys.""" - @abstractmethod - def set(self, mapping: Mapping[str, tuple[T, int | None]]) -> None: - """Set the cached values for the given keys and TTLs.""" - - @abstractmethod - def delete(self, keys: Sequence[str]) -> None: - """Delete the cached values for the given keys.""" - @abstractmethod async def aget(self, keys: Sequence[str]) -> dict[str, T]: """Asynchronously get the cached values for the given keys.""" + @abstractmethod + def set(self, mapping: Mapping[str, tuple[T, int | None]]) -> None: + """Set the cached values for the given keys and TTLs.""" + @abstractmethod async def aset(self, mapping: Mapping[str, tuple[T, int | None]]) -> None: """Asynchronously set the cached values for the given keys and TTLs.""" + @abstractmethod + def delete(self, keys: Sequence[str]) -> None: + """Delete the cached values for the given keys.""" + @abstractmethod async def adelete(self, keys: Sequence[str]) -> None: """Asynchronously delete the cached values for the given keys.""" diff --git a/libs/checkpoint/langgraph/cache/file/__init__.py b/libs/checkpoint/langgraph/cache/file/__init__.py index 482d8d357..2ed206abf 100644 --- a/libs/checkpoint/langgraph/cache/file/__init__.py +++ b/libs/checkpoint/langgraph/cache/file/__init__.py @@ -28,25 +28,25 @@ class FileCache(BaseCache): if key in self._db } + async def aget(self, keys: list[str]) -> dict[str, bytes]: + """Asynchronously get the cached values for the given keys.""" + return await asyncio.to_thread(self.get, keys) + def set(self, mapping: dict[str, tuple[bytes, int | None]]) -> None: """Set the cached values for the given keys and TTLs.""" for key, (value, _) in mapping.items(): # File-based caches do not support TTLs, so we ignore them. self._db[key] = ormsgpack.packb(self.serde.dumps_typed(value)) + async def aset(self, mapping: dict[str, tuple[bytes, int | None]]) -> None: + """Asynchronously set the cached values for the given keys and TTLs.""" + await asyncio.to_thread(self.set, mapping) + def delete(self, keys: list[str]) -> None: """Delete the cached values for the given keys.""" for key in keys: self._db.pop(key, None) - async def aget(self, keys: list[str]) -> dict[str, bytes]: - """Asynchronously get the cached values for the given keys.""" - return await asyncio.to_thread(self.get, keys) - - async def aset(self, mapping: dict[str, tuple[bytes, int | None]]) -> None: - """Asynchronously set the cached values for the given keys and TTLs.""" - await asyncio.to_thread(self.set, mapping) - async def adelete(self, keys: list[str]) -> None: """Asynchronously delete the cached values for the given keys.""" await asyncio.to_thread(self.delete, keys)