fix: add usage example to Caching class, remove pickle fallback

- Add docstring with usage example to Caching class matching the
  convention used by sibling APIs (Execution.set_progress, ComfyExtension)
- Remove non-deterministic pickle fallback from _serialize_cache_key;
  return None on JSON failure instead of producing unretrievable hashes
- Move cache_provider imports to top of execution.py (no circular dep)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Deep Mehta
2026-03-03 17:41:33 -08:00
parent 66ad9937c8
commit c73e3c9619
3 changed files with 20 additions and 11 deletions

View File

@@ -5,7 +5,6 @@ import hashlib
import json
import logging
import math
import pickle
import threading
_logger = logging.getLogger(__name__)
@@ -143,13 +142,7 @@ def _serialize_cache_key(cache_key: Any) -> Optional[str]:
return hashlib.sha256(json_str.encode('utf-8')).hexdigest()
except Exception as e:
_logger.warning(f"Failed to serialize cache key: {e}")
# Fallback to pickle (non-deterministic but better than nothing)
try:
serialized = pickle.dumps(cache_key, protocol=4)
return hashlib.sha256(serialized).hexdigest()
except Exception as fallback_error:
_logger.warning(f"Failed pickle fallback for cache key: {fallback_error}")
return None
return None
def _contains_nan(obj: Any) -> bool: