From 2049066cffa256fe9313d25072e7a17d2cce2f58 Mon Sep 17 00:00:00 2001 From: Deep Mehta Date: Thu, 29 Jan 2026 19:42:34 +0530 Subject: [PATCH] refactor: expose CacheProvider API via comfy_api.latest.Caching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add Caching class to comfy_api/latest/__init__.py that re-exports from comfy_execution.cache_provider (source of truth) - Fix docstring: "Skip large values" instead of "Skip small values" (small compute-heavy values are good cache targets) - Maintain backward compatibility: comfy_execution.cache_provider imports still work Usage: from comfy_api.latest import Caching class MyProvider(Caching.CacheProvider): def on_lookup(self, context): ... def on_store(self, context, value): ... Caching.register_provider(MyProvider()) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- comfy_api/latest/__init__.py | 37 +++++++++++++++++++++++++++++++ comfy_execution/cache_provider.py | 5 ++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/comfy_api/latest/__init__.py b/comfy_api/latest/__init__.py index b0fa14ff6..1a1b6d162 100644 --- a/comfy_api/latest/__init__.py +++ b/comfy_api/latest/__init__.py @@ -106,6 +106,42 @@ class Types: MESH = MESH VOXEL = VOXEL + +class Caching: + """ + External cache provider API for distributed caching. + + Enables sharing cached results across multiple ComfyUI instances + (e.g., Kubernetes pods) without monkey-patching internal methods. + + Example usage: + from comfy_api.latest import Caching + + class MyRedisProvider(Caching.CacheProvider): + def on_lookup(self, context): + # Check Redis for cached result + ... + + def on_store(self, context, value): + # Store to Redis (can be async internally) + ... + + Caching.register_provider(MyRedisProvider()) + """ + # Import from comfy_execution.cache_provider (source of truth) + from comfy_execution.cache_provider import ( + CacheProvider, + CacheContext, + CacheValue, + register_cache_provider as register_provider, + unregister_cache_provider as unregister_provider, + get_cache_providers as get_providers, + has_cache_providers as has_providers, + clear_cache_providers as clear_providers, + estimate_value_size, + ) + + ComfyAPI = ComfyAPI_latest # Create a synchronous version of the API @@ -125,6 +161,7 @@ __all__ = [ "Input", "InputImpl", "Types", + "Caching", "ComfyExtension", "io", "IO", diff --git a/comfy_execution/cache_provider.py b/comfy_execution/cache_provider.py index 69ae9a99c..63fba5632 100644 --- a/comfy_execution/cache_provider.py +++ b/comfy_execution/cache_provider.py @@ -4,6 +4,9 @@ External Cache Provider API for distributed caching. This module provides a public API for external cache providers, enabling distributed caching across multiple ComfyUI instances (e.g., Kubernetes pods). +Public API is also available via: + from comfy_api.latest import Caching + Example usage: from comfy_execution.cache_provider import ( CacheProvider, CacheContext, CacheValue, register_cache_provider @@ -120,7 +123,7 @@ class CacheProvider(ABC): Common filters: - By class_type: Only expensive nodes (KSampler, VAEDecode) - - By size: Skip small values (< 1MB) + - By size: Skip large values to reduce network overhead Default: Returns True (cache everything). """