Nodes/SP-Nodes/SP_CompositeCacheKey
ComfyUI Node

SP_CompositeCacheKey

Build a cache key that actually changes when your inputs do

By bananasss00·Created 2 years ago·Updated 12 days ago· 20
SP_CompositeCacheKey
    • key
    prefix
    separator_
    part_A
    part_B
    part_C

    Every node in this pack's cache family - SP_CacheAutoLoader, SP_CacheValue, SP_CacheStore, SP_CacheGet, SP_CacheCheck - keys off a plain string you type in. That's fine for a single cache point in a simple graph, and a real liability the moment you have more than one: two nodes left at the default default_key, or two branches of a workflow that should cache separately but happen to share a hand-typed string, will silently collide. SP_CompositeCacheKey is the fix - it builds a key out of multiple parts so you can make it actually unique, ideally by wiring in something that changes when the thing you're caching changes.

    How it works

    It's a string-joining node, nothing more exotic: a prefix, up to three optional middle parts, and a separator to glue them together into one key string. Feed it something meaningful in part_A/part_B/part_C - a model name, a resolution, a seed as a string - and the resulting key changes automatically when those inputs change, which is exactly the invalidation behavior the rest of the cache family doesn't give you for free.

    Inputs and outputs

    • prefix (STRING, required, default empty) - the leading part of the key, typically a fixed label like "caption" or "upscale".
    • separator (STRING, required, default _) - what joins the parts together.
    • part_A, part_B, part_C (STRING, all optional, default empty) - the variable pieces. Leave any unused ones empty.
    • Output: key (STRING) - feed this straight into any of the other SP_Cache nodes' key input.

    Installing it

    ComfyUI Manager: search "SP-Nodes", install, restart. Manually:

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

    then restart ComfyUI. No dependencies beyond the base pack.

    Common issues

    The key still doesn't change when you expect it to. This node only reacts to what you actually wire into part_A/part_B/part_C - if the thing that determines your output (say, a seed or a prompt) isn't one of those parts, the key stays constant and you're back to stale-cache territory. Include whatever genuinely varies the result, not just a static label.

    Empty parts produce an odd-looking key. Unused parts default to empty strings, so with separator set to _ you might get something like caption__512 with a doubled separator where a skipped part sat. That's cosmetic - it's still a valid, unique-enough string - but if it bothers you, only wire the parts you're actually using and leave the rest disconnected rather than passing empty strings explicitly.

    Two workflows use the same prefix and parts by coincidence. If you're sharing a cache_directory (via SP_CacheAutoLoader) across multiple projects or workflows, a composite key built the same way in both will still collide. Add something workflow-specific to prefix if that's a real risk for you.

    CategorySP-Nodes/cache

    Inputs (5)

    NameTypeDefaultDescription
    prefixSTRINGThe initial part of the key.
    separatorSTRING_The character or string used to join the key parts.
    part_AoptSTRINGAn optional middle part of the key.
    part_BoptSTRINGAnother optional middle part of the key.
    part_CoptSTRINGAn optional final part of the key.

    Outputs (1)

    NameTypeDescription
    keySTRING