Prompt caching
Control per-client managed-prompt freshness, reloads and invalidation.
Only managedPrompts uses this cache. It does not cache management lists or AI completions. Defaults are enabled, 60-second TTL, 100 prompt variants per instance. Default reads deduplicate concurrent misses by identifier/version.
import { Nirmos } from "@nirmos/sdk";
const key = process.env.NIRMOS_API_KEY;
if (!key) throw new Error("Missing NIRMOS_API_KEY");
const nirmos = new Nirmos({
auth: { type: "api-key", key },
promptCache: { enabled: true, ttlMs: 120_000, maxEntries: 250 },
});Set promptCache: false or enabled: false to disable stored entries. All selections (active/latest/numeric) may be cached. TTL zero expires stored entries immediately; concurrent default lookups can still share an in-flight request.
Retrieval modes
| Mode | Read stored cache | Store result |
|---|---|---|
default | Yes; share a matching in-flight read | Yes |
reload | No; perform fresh read | Yes |
no-store | No; perform fresh read | No |
const fresh = await nirmos.managedPrompts.retrieve("support-reply", { cache: "reload" });
const uncached = await nirmos.managedPrompts.retrieve("support-reply", { cache: "no-store" });
console.log(fresh.version.number, uncached.version.number);Prompt references in chat accept the same cache modes. Local mutations under managedPrompts invalidate stored entries. Control-plane prompts changes do not invalidate this cache automatically.
nirmos.managedPrompts.clearCache();
// Or clear stored variants addressed by this identifier:
nirmos.managedPrompts.clearCache("support-reply");Clearing does not cancel in-flight reads; those can repopulate stored entries. ID and slug are different lookup keys, so a full clear is safer after an external change. There is no distributed cache adapter or automatic cross-process invalidation.