prompt-cache

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).

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "prompt-cache" with this command: npx skills add nissan/prompt-cache

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

  1. Normalize the prompt (lowercase, collapse whitespace)
  2. Combine with context keys (user name, language, model)
  3. SHA-256 hash the combined key
  4. Check cache table for existing result
  5. On miss: call API, store result. On hit: return cached result instantly.

Usage

import prompt_cache

# Check before calling expensive API
cached = await prompt_cache.get_cached(
    prompt="Tell me a story about clouds",
    child_name="Sophie",
    language="fr"
)

if cached:
    return cached  # Free! No API call needed.

# Cache miss — call the API
result = await generate_story(prompt, child_name, language)

# Store for next time
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)

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Airplane AI / 断网 AI 助手

Give LM Studio or Ollama users a browser-based AI chat interface that works completely offline. Use when the user wants an offline-capable personal AI, needs...

Registry SourceRecently Updated
General

佛学导师 (The Buddhist Mentor )

提供系统化的佛学学习指导,分阶段引导理解核心概念、经典解读与实际应用,助力自我觉察与智慧拓展。

Registry SourceRecently Updated
General

Secretary Memory

OpenClaw 秘书式多分区记忆系统 v3.0。仿生现代秘书的笔记本分类法,支持:(1) 多分区并发搜索 + 每分区3条上下文召回,(2) 会话自动摘要,(3) 偏好自动提取 + 用户关系图谱,(4) 记忆冲突主动检测,(5) 定时 consolidation + 会话结束 hook,(6) 精细化恢复/回溯,...

Registry SourceRecently Updated
General

sendbl

Create sendbl file-exchange links — request files from someone, send a file, check link status, list files in a link, or delete a link. Use when the user wan...

Registry SourceRecently Updated