SP_CacheRouter
An if/else gate that checks your cache before deciding which branch runs
- if_cached_flow
- if_not_cached_flow
- routed_output
- status
SP_CacheRouter is the branch in a "did I already do this?" workflow. It looks at a key, checks whether that key exists in the cache - memory or disk, single-value or multi-slot - and then routes execution down one of two paths: the "cached" branch or the "not cached" branch. It's ComfyUI's if (cache exists) / else, except the condition isn't a value you compute, it's the state of your cache.
Why would you want that? Because it turns "render everything, always" into "render the new stuff, reuse the rest." The classic pattern is a batch of jobs: you render a folder of videos, cache each result under its job name, and on the next run the router sees a key exists and skips straight to the downstream nodes that stitch the cached results together. Only genuinely new jobs travel the not-cached branch.
How it works
The check is deliberately broad: for the key you give it, it looks in the in-memory dictionary and on disk, and it checks both the single-value file (<key>.joblib) and the multi-slot files (<key>_multi.joblib). Any hit counts as cached. Both branch inputs - if_cached_flow and if_not_cached_flow - are lazy, and check_lazy_status requests only the branch that's actually needed. The losing branch never evaluates, which is the whole point: if the result is cached, the expensive render nodes on the other side of the graph never run.
You get two outputs: routed_output (the value from whichever branch won) and a status string that tells you "Routed -> CACHED FLOW" or "Routed -> NOT CACHED FLOW".
The inputs that matter
- key - the entry you're asking about. Must match what the loader nodes write, exactly.
- cache_directory - where the cache files live. Default
sp_node_cache, relative to ComfyUI's working directory. If this doesn't match what the cache-writing nodes use, the router will always say "not cached" and the smart-branching silently degrades into always-recompute. - if_cached_flow / if_not_cached_flow - the two candidate values. Only the winning one is evaluated.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/bananasss00/ComfyUI-SP-Nodes
then restart, or grab "SP-Nodes" through ComfyUI Manager. Nothing extra to download; joblib from the pack's requirements.txt does the disk work.
Where people get burned
Existence is the only thing this node checks - not freshness. A stale key still counts as "cached," so if you cache an entry and later change what should produce it, the router will keep routing to the cached branch. Pair it with SP_CacheSmartHashKey (key derives from inputs, so changes invalidate) or bump your keys when the underlying recipe changes. And if the router's cache_directory doesn't line up with the loader's, you'll never get a hit - check the folder next to ComfyUI, not inside the custom node.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| key | STRING | default_key | — |
| cache_directory | STRING | sp_node_cache | — |
| if_cached_flowopt | * | Evaluated and passed ONLY if the cache EXISTS. | |
| if_not_cached_flowopt | * | Evaluated and passed ONLY if the cache is MISSING. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| routed_output | * | — |
| status | STRING | — |