From 736055ddd3d0913572fb5e4b2a0a0ce591828777 Mon Sep 17 00:00:00 2001 From: Eugene Batalov Date: Wed, 18 Dec 2024 16:47:04 +0000 Subject: [PATCH] Delete unused code: CacheAwareFunctionWrapper There no known roadmap items to implement local caching for local graph executions. So let's delete this code. Testing: make check make test --- python-sdk/indexify/functions_sdk/graph.py | 2 - .../indexify/functions_sdk/local_cache.py | 46 ------------------- 2 files changed, 48 deletions(-) delete mode 100644 python-sdk/indexify/functions_sdk/local_cache.py diff --git a/python-sdk/indexify/functions_sdk/graph.py b/python-sdk/indexify/functions_sdk/graph.py index f66091710..8ce2d981d 100644 --- a/python-sdk/indexify/functions_sdk/graph.py +++ b/python-sdk/indexify/functions_sdk/graph.py @@ -37,7 +37,6 @@ IndexifyRouter, RouterCallResult, ) -from .local_cache import CacheAwareFunctionWrapper from .object_serializer import get_serializer RouterFn = Annotated[ @@ -86,7 +85,6 @@ def __init__( # Storage for local execution self._results: Dict[str, Dict[str, List[IndexifyData]]] = {} - self._cache = CacheAwareFunctionWrapper("./indexify_local_runner_cache") self._accumulator_values: Dict[str, IndexifyData] = {} self._local_graph_ctx: Optional[GraphInvocationContext] = None diff --git a/python-sdk/indexify/functions_sdk/local_cache.py b/python-sdk/indexify/functions_sdk/local_cache.py deleted file mode 100644 index 409164606..000000000 --- a/python-sdk/indexify/functions_sdk/local_cache.py +++ /dev/null @@ -1,46 +0,0 @@ -import os -from hashlib import sha256 -from typing import List, Optional - - -class CacheAwareFunctionWrapper: - def __init__(self, cache_dir: str): - self._cache_dir = cache_dir - if not os.path.exists(cache_dir): - os.makedirs(cache_dir) - - def _get_key(self, input: bytes) -> str: - h = sha256() - h.update(input) - return h.hexdigest() - - def get(self, graph: str, node_name: str, input: bytes) -> Optional[List[bytes]]: - key = self._get_key(input) - dir_path = os.path.join(self._cache_dir, graph, node_name, key) - if not os.path.exists(dir_path): - return None - - files = os.listdir(dir_path) - outputs = [] - for file in files: - with open(os.path.join(dir_path, file), "rb") as f: - return f.read() - - return outputs - - def set( - self, - graph: str, - node_name: str, - input: bytes, - output: List[bytes], - ): - key = self._get_key(input) - dir_path = os.path.join(self._cache_dir, graph, node_name, key) - if not os.path.exists(dir_path): - os.makedirs(dir_path) - - for i, output_item in enumerate(output): - file_path = os.path.join(dir_path, f"{i}.cbor") - with open(file_path, "wb") as f: - f.write(output_item)