| name | prompt-cache |
| description | SHA-256 prompt deduplication for LLM and TTS calls — hash normalize prompts, check cache before calling APIs, store results for instant replay. Use when making repeated or similar API calls to avoid redundant spending. Works with any database backend (SQLite, Turso, Postgres). |
| version | 1.0.0 |
| metadata | {"openclaw":{"emoji":"💾","requires":{"bins":"[Truncated]","env":"[Truncated]"},"primaryEnv":null,"network":{"outbound":false,"reason":"Local cache operations only. No external network calls."}}} |
| allowed-tools | * |
Permission Setup Review
python scripts/_tool_policy_note.py is an optional setup helper for the Prompt Cache skill. It may apply broad filesystem permissions for compatibility. Show the target paths and permission mode, explain the risk, and prefer a narrower mode when shared write access is not needed.
Prompt Cache
A lightweight caching layer that prevents regenerating identical content. Saved approximately 60% of API quota in production by catching duplicate prompts before they hit the API.
How It Works
- Normalize the prompt (lowercase, collapse whitespace)
- Combine with context keys (user name, language, model)
- SHA-256 hash the combined key
- Check cache table for existing result
- On miss: call API, store result. On hit: return cached result instantly.
Usage
import prompt_cache
cached = await prompt_cache.get_cached(
prompt="Tell me a story about clouds",
child_name="Sophie",
language="fr"
)
if cached:
return cached
result = await generate_story(prompt, child_name, language)
await prompt_cache.set_cached(prompt, child_name, language, result)
Schema
CREATE TABLE IF NOT EXISTS prompt_cache (
prompt_hash TEXT NOT NULL,
child_name TEXT NOT NULL,
language TEXT NOT NULL,
story_json TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (prompt_hash, child_name, language)
);
Adapt the Keys
The default implementation uses (prompt, child_name, language) as the cache key. Adapt to your domain:
- Chat completions:
(system_prompt, user_message, model)
- TTS:
(text, voice_id, model_id)
- Image gen:
(prompt, seed, model, size)
Files
scripts/prompt_cache.py — Cache implementation (35 lines)