77
88from typing import TYPE_CHECKING , ClassVar
99
10+ from graphrag .cache .json_pipeline_cache import JsonPipelineCache
11+ from graphrag .cache .memory_pipeline_cache import InMemoryCache
12+ from graphrag .cache .noop_pipeline_cache import NoopPipelineCache
1013from graphrag .config .enums import CacheType
1114from graphrag .storage .blob_pipeline_storage import BlobPipelineStorage
1215from graphrag .storage .cosmosdb_pipeline_storage import CosmosDBPipelineStorage
1720
1821 from graphrag .cache .pipeline_cache import PipelineCache
1922
20- from graphrag .cache .json_pipeline_cache import JsonPipelineCache
21- from graphrag .cache .memory_pipeline_cache import InMemoryCache
22- from graphrag .cache .noop_pipeline_cache import NoopPipelineCache
23-
24-
25- def create_noop_cache (** _kwargs ) -> PipelineCache :
26- """Create a no-op cache implementation."""
27- return NoopPipelineCache ()
28-
29-
30- def create_memory_cache (** _kwargs ) -> PipelineCache :
31- """Create an in-memory cache implementation."""
32- return InMemoryCache ()
33-
34-
35- def create_file_cache (root_dir : str , base_dir : str , ** kwargs ) -> PipelineCache :
36- """Create a file-based cache implementation."""
37- # Create storage with base_dir in kwargs since FilePipelineStorage expects it there
38- storage_kwargs = {"base_dir" : root_dir , ** kwargs }
39- storage = FilePipelineStorage (** storage_kwargs ).child (base_dir )
40- return JsonPipelineCache (storage )
41-
42-
43- def create_blob_cache (** kwargs ) -> PipelineCache :
44- """Create a blob storage-based cache implementation."""
45- storage = BlobPipelineStorage (** kwargs )
46- return JsonPipelineCache (storage )
47-
48-
49- def create_cosmosdb_cache (** kwargs ) -> PipelineCache :
50- """Create a CosmosDB-based cache implementation."""
51- storage = CosmosDBPipelineStorage (** kwargs )
52- return JsonPipelineCache (storage )
53-
5423
5524class CacheFactory :
5625 """A factory class for cache implementations.
@@ -69,7 +38,7 @@ def register(cls, cache_type: str, creator: Callable[..., PipelineCache]) -> Non
6938
7039 Args:
7140 cache_type: The type identifier for the cache.
72- creator: A callable that creates an instance of the cache .
41+ creator: A class or callable that creates an instance of PipelineCache .
7342
7443 Raises
7544 ------
@@ -100,7 +69,7 @@ def create_cache(
10069 ValueError: If the cache type is not registered.
10170 """
10271 if not cache_type or cache_type == CacheType .none :
103- return create_noop_cache ()
72+ return NoopPipelineCache ()
10473
10574 type_str = cache_type .value if isinstance (cache_type , CacheType ) else cache_type
10675
@@ -126,8 +95,28 @@ def is_supported_type(cls, cache_type: str) -> bool:
12695
12796
12897# --- register built-in cache implementations ---
129- CacheFactory .register (CacheType .none .value , create_noop_cache )
130- CacheFactory .register (CacheType .memory .value , create_memory_cache )
98+ def create_file_cache (root_dir : str , base_dir : str , ** kwargs ) -> PipelineCache :
99+ """Create a file-based cache implementation."""
100+ # Create storage with base_dir in kwargs since FilePipelineStorage expects it there
101+ storage_kwargs = {"base_dir" : root_dir , ** kwargs }
102+ storage = FilePipelineStorage (** storage_kwargs ).child (base_dir )
103+ return JsonPipelineCache (storage )
104+
105+
106+ def create_blob_cache (** kwargs ) -> PipelineCache :
107+ """Create a blob storage-based cache implementation."""
108+ storage = BlobPipelineStorage (** kwargs )
109+ return JsonPipelineCache (storage )
110+
111+
112+ def create_cosmosdb_cache (** kwargs ) -> PipelineCache :
113+ """Create a CosmosDB-based cache implementation."""
114+ storage = CosmosDBPipelineStorage (** kwargs )
115+ return JsonPipelineCache (storage )
116+
117+
118+ CacheFactory .register (CacheType .none .value , NoopPipelineCache )
119+ CacheFactory .register (CacheType .memory .value , InMemoryCache )
131120CacheFactory .register (CacheType .file .value , create_file_cache )
132121CacheFactory .register (CacheType .blob .value , create_blob_cache )
133122CacheFactory .register (CacheType .cosmosdb .value , create_cosmosdb_cache )
0 commit comments