Nodes/SP-Nodes/SP_CacheValue
ComfyUI Node

SP_CacheValue

Cache a value once, reuse it until you say otherwise

By bananasss00·Created 2 years ago·Updated 12 days ago· 20
SP_CacheValue
  • value
  • value
keydefault_key
overwritefalse

SP_CacheValue sits between SP_CacheStore's always-overwrite behavior and SP_CacheGet's never-write behavior: cache a value once under a key, and on every run after that, hand back what's cached instead of recomputing - unless you flip overwrite on, in which case it behaves exactly like SP_CacheStore and refreshes the entry. The pack's description says it plainly: "Caches a value. If 'overwrite' is True, it acts like CacheStore."

This is the node to use for the common case: compute something once, reuse it on every subsequent queue press, until you deliberately want it recomputed.

How it works

On a cache miss (nothing yet stored under key) or when overwrite is true, the upstream node feeding value gets evaluated and the result stored. On a cache hit with overwrite false, the cached value comes back and - going by the schema, which gives this node no cache_directory parameter the way SP_CacheAutoLoader has - that caching looks to be in-memory rather than disk-backed. If you need a value cached with SP_CacheValue to survive a ComfyUI restart, pair it with a manual SP_CachePersistence save_to_disk step, or use SP_CacheAutoLoader instead if you want that handled automatically.

Inputs and outputs

  • key (STRING, required, default default_key) - the cache identifier.
  • overwrite (BOOLEAN, required, default false) - false means "use the cache if it exists"; true forces a fresh compute and re-stores it, same as SP_CacheStore.
  • value (optional, any type) - evaluated only on a miss or when overwriting, per the tooltip.
  • Output: value - the cached or freshly computed result.

This node is also marked an output node, so it runs for its caching side effect even without a connected output.

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. No extra dependencies for this node specifically.

Common issues

Output looks stuck after you changed something upstream. Same trap as the rest of the cache family: the key doesn't know your inputs changed, so a hit under the old key returns the old result. Toggle overwrite to true for one run to force a refresh, or clear the key with SP_CacheManager.

Confusing this with SP_CacheAutoLoader. They look similar - both take a key and a lazily-evaluated value - but CacheAutoLoader adds disk persistence and an enabled kill switch; CacheValue trades that for a manual overwrite toggle and, going by the schema, stays in memory. Pick CacheAutoLoader if you want the cache to survive a restart without extra steps; pick CacheValue if you want an explicit, single-flag way to force a refresh.

Restarting ComfyUI loses everything. If this node's cache is memory-only, a restart clears it and the next run recomputes from scratch - which is correct behavior, just worth expecting rather than being surprised by.

CategorySP-Nodes/cache

Inputs (3)

NameTypeDefaultDescription
keySTRINGdefault_keyThe unique key for this cache entry.
overwriteBOOLEANfalseIf True, always re-evaluate the input and overwrite the existing cache entry.
valueopt*The value to cache. This is only evaluated on a cache miss or when 'overwrite' is True.

Outputs (1)

NameTypeDescription
value*