Nodes/ComfyUI Inspire Pack/Cache Backend Data [NumberKey] (Inspire)
ComfyUI Node Runs on cloud

Cache Backend Data [NumberKey] (Inspire)

Memory cache keyed by a number, for automation

By ltdrdata·Created 3 years ago·Updated 9 months ago· 805
Cache Backend Data [NumberKey] (Inspire)
  • data
  • data opt
key0
tag

Same idea as Inspire's regular backend cache, with one change: the key is an integer instead of a string. You hand it some data and a number; it stashes that data in ComfyUI's memory so you - or another workflow - can pull it back with the matching Retrieve Backend Data [NumberKey] node using the same number. That's the whole difference, and it exists for one reason: automation.

When you're driving a workflow programmatically, or iterating with a counter, an integer key is far easier to generate than a string. Loop index 0, 1, 2, 3 becomes your cache key directly - no string formatting, no "item_" + str(i). If you're caching one object per iteration and want to fetch them back by position later, number keys are the natural fit.

How it works

Inspire's backend cache is a key→value store living in the backend process, separate from the graph, so entries survive across queue runs and workflow switches and get wiped on a ComfyUI restart (it's memory, not disk). This node writes into that store under an integer key, grouped by tag. Retrieve it later by feeding the same number to the NumberKey retrieve node. The value is a wildcard type, so it can be a model, a latent, an image, a string - anything.

One caution worth stating up front: this is the single-item version. If you pipe a list into it, ComfyUI runs it once per item and each run overwrites the same number key - so you'd cache only the last element. For lists, use Cache Backend Data List [NumberKey] instead, or give each element its own unique key.

The inputs and outputs that matter

  • key (INT) - the number you store under and retrieve by. Reuse it in a retrieve node to get the data; reuse it in another cache node to overwrite.
  • tag (STRING) - a grouping label. Each tag carries a max entry count (default around 5); exceed it and the oldest entries under that tag get evicted.
  • data (type *) - the object you're caching. Anything.

The output is data opt (type *) - a pass-through of the same data, so you can splice this node inline. It's also an output node, so it can sit at the end of a branch just to do the caching.

How to install it

ComfyUI Manager: search ComfyUI Inspire Pack, install, restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Inspire-Pack

then restart. It's a Dr.Lt.Data pack (also ComfyUI-Manager and the Impact Pack).

Common issues & troubleshooting

Retrieve returns nothing. The number keys must match exactly, and the cache node has to have actually run before the retrieve reads. Across separate workflows, run the caching one first.

I fed it a list and only one thing came back. Right - this single-item node overwrites the same key per list element. Switch to Cache Backend Data List [NumberKey], which caches the combined list, or assign each element a distinct number.

Gone after a restart. Expected. In-memory cache, not disk. Save to disk if you need persistence.

An entry disappeared on its own. Tag size cap (default ~5). Give important data its own tag or raise the tag's size via Show Cached Info.

Order looks wrong / it caches too late. ComfyUI doesn't order unconnected branches. Chain the consumer to the data opt pass-through so there's a real dependency.

Memory keeps growing. You're caching heavy objects and never clearing. Use Remove Backend Data [NumberKey] to free a key when done.

CategoryInspirePack/Backend

Inputs (3)

NameTypeDefaultDescription
keyINT00–18446744073709550000
tagSTRING
data*

Outputs (1)

NameTypeDescription
data opt*