Nodes/SP-Nodes/SP_CacheSmartHashKey
ComfyUI Node

SP_CacheSmartHashKey

A cache key that changes itself when your inputs change

By bananasss00·Created 2 years ago·Updated 14 days ago· 24
SP_CacheSmartHashKey
  • arg_1
  • arg_2
  • arg_3
  • arg_4
  • arg_5
  • arg_6
  • arg_7
  • arg_8
  • hash_key
  • arg_1
  • arg_2
  • arg_3
  • arg_4
  • arg_5
  • arg_6
  • arg_7
  • arg_8
prefixjob

The whole failure mode of manual cache keys is remembering to change them. You cache something under my_key, tweak a parameter, rerun, and get last run's values back because the key never changed. SP_CacheSmartHashKey exists to remove that failure mode: instead of you picking a key, it hashes up to eight of your inputs together and produces a key that changes whenever the inputs change.

It takes arg_1 through arg_8 (any type, all optional), concatenates every connected one with | separators, runs MD5 over the result, and returns prefix_ plus the first ten hex characters. Change a seed, change the hash; change nothing, the hash stays - which is exactly the behavior a cache key wants.

How it works

The trick is that it does this without breaking your graph's wiring. The node passes all eight inputs straight through to matching outputs unchanged, so you can drop it inline and the values keep flowing. The hash_key output is the extra tap you route into a cache node's key input. It also implements IS_CHANGED by recomputing the same hash, so ComfyUI's own change detection agrees about when the node's output is actually different.

This is the glue for the pack's other cache nodes. Wire hash_key into SP_CacheAutoLoaderMulti (or the router) and the key self-invalidates: any upstream change produces a new key, which produces a cache miss, which recomputes. No manual key bumping, no stale-results debugging sessions.

The inputs and outputs that matter

  • prefix - the readable label in front of the hash, default job. Make it meaningful (flux_ultra, render_batch) because you'll see it in cache filenames.
  • arg_1arg_8 - whatever drives the job. Only connected inputs feed the hash, so if you want an arg to affect the key, wire it in.
  • Outputs: hash_key plus the eight args, passed through untouched.

One honest caveat: ten hex characters is 40 bits, and MD5 is not a cryptographic primitive - fine for personal cache keys, not something to rely on against an adversary or for trillions of entries. For a workflow cache it's plenty.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/bananasss00/ComfyUI-SP-Nodes

restart, or install "SP-Nodes" via ComfyUI Manager. No extra dependencies beyond what the pack already installs - hashing is stdlib.

Where people get burned

The "only connected args count" rule cuts both ways. If you forget to wire an input you think is part of the job's identity, the key won't change when it changes - silent staleness. And keep prefix distinct per job type; two workflows sharing a prefix and identical inputs would collide. Cheap fix: unique prefixes per workflow.

CategorySP-Nodes/cache

Inputs (9)

NameTypeDefaultDescription
prefixSTRINGjobPrefix for the generated hash string.
arg_1opt*
arg_2opt*
arg_3opt*
arg_4opt*
arg_5opt*
arg_6opt*
arg_7opt*
arg_8opt*

Outputs (9)

NameTypeDescription
hash_keySTRING
arg_1*
arg_2*
arg_3*
arg_4*
arg_5*
arg_6*
arg_7*
arg_8*