Nodes/ComfyUI_MieNodes/Load Or Compute ๐Ÿ‘
ComfyUI Node

Load Or Compute ๐Ÿ‘

Compute once, cache it, skip the work next time

By MieMieeeeeยทCreated 2 years agoยทUpdated 28 days agoยท 225
Load Or Compute ๐Ÿ‘
  • value
  • value
โ—„cache_pathoutput/cache/foo.pklโ–บ

This is the memoize pattern as a node: if a cached result exists on disk, load and return it; if it doesn't, take the freshly computed value, save it, and return that. Run your workflow once and the expensive step is cached; run it again and you get the stored result instead of paying for the computation twice.

It's part of ComfyUI-MieNodes (ComfyUI_MieNodes), MieMieeeee's utility pack, under ๐Ÿ‘ Common. It's the write-enabled half of a pair with LoadAny.

Why you'd reach for it

Anyone iterating on a big graph knows the pain: you tweak one thing near the end, hit run, and sit through a five-minute step near the start that produced the exact same output it did last time. Caching that step means you only pay for it when its result actually changes. That's a real cycle-time win when you're iterating, and it's exactly the kind of thing ComfyUI doesn't give you out of the box.

The classic uses: a captioning or vision pass over a fixed image, an embedding you'll reuse, a slow preprocessing result, anything deterministic and expensive that you don't want to redo on every render while you're tuning the parts downstream of it.

How it works

You provide a cache_path and a value. On a cache miss (no file at that path), the node takes the incoming value, writes it to disk, and passes it through. On a cache hit (the file exists), it loads the stored value and returns that - the goal being to skip the recomputation entirely rather than just overwrite it. The default output/cache/foo.pkl again points at pickle serialization, which is why value is typed * and can be anything: an image, a string, a dict, a model-ish blob.

The mental model: the cache_path is the cache key. Same path means "this is the same computation" - so if you change the upstream inputs in a way that should invalidate the cache, you need to change the path (or delete the file), because the node trusts the path, not the contents of what fed it.

The inputs and outputs that matter

  • cache_path (STRING, required) - the cache file. This doubles as the cache key. Default output/cache/foo.pkl.
  • value (any, required) - the freshly computed result, wired from the expensive upstream node. Used (and saved) only on a cache miss.
  • value (any, output) - the cached result on a hit, or the passed-through/just-saved value on a miss.

Installing it

ComfyUI Manager โ†’ search ComfyUI-MieNodes โ†’ install โ†’ restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/MieMieeeee/ComfyUI-MieNodes

then restart. No model download. Nodes appear under ๐Ÿ‘ MieNodes.

Common issues & troubleshooting

Stale cache after you changed the inputs. This is the big one. The node keys on cache_path, not on what feeds value, so if you change something upstream but keep the same path, you'll keep getting the old cached result. Fix: use a fresh cache_path per meaningful variation, or delete the cache file to force a recompute. A handy trick is to build the path from a hash of the inputs so it changes when they do.

Pickle safety. Same caveat as LoadAny - the cache is a pickle, and you should only ever load pickles your own workflows wrote. Don't point cache_path at a file from an untrusted source.

It didn't skip the expensive upstream node. Whether the upstream work is actually avoided depends on how ComfyUI evaluates the graph feeding value. If you find it still running the slow step on a cache hit, the win you're guaranteed is the saved result being reused; structure the graph so the heavy node genuinely sits behind this one.

Cache folder filling up. Every distinct cache_path is a file on disk, and pickled tensors are not small. Clean out output/cache periodically, or you'll wonder where your disk went.

Category๐Ÿ‘ MieNodes/๐Ÿ‘ Common

Inputs (2)

NameTypeDefaultDescription
cache_pathSTRINGoutput/cache/foo.pklโ€”
value*โ€”

Outputs (1)

NameTypeDescription
value*โ€”