openrouter-caching-strategy
Implement response caching to reduce costs and latency. Use when dealing with repeated queries or high-volume scenarios. Trigger with phrases like 'openrouter cache', 'cache responses', 'openrouter caching', 'reduce api calls'.
- License 许可
- MIT
- 最近更新
- 2026-05-26
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- openrouter-caching-strategy
- author
- Jeremy Longshore <jeremy@intentsolutions.io>
- license
- MIT
- version
- 1.0.0
- description
- Implement response caching to reduce costs and latency. Use when dealing with repeated queries or high-volume scenarios. Trigger with phrases like 'openrouter cache', 'cache responses', 'openrouter caching', 'reduce api calls'.
- allowed-tools
- Read, Write, Edit, Grep
- compatible-with
- claude-code, codex, openclaw
02 资源文件 8
- 参考文档references/cache-invalidation.md988 B
- 参考文档references/caching-strategies.md2.4 KB
- 参考文档references/cost-savings-analysis.md1.4 KB
- 参考文档references/errors.md323 B
- 参考文档references/examples.md4.1 KB
- 参考文档references/in-memory-caching.md2.5 KB
- 参考文档references/redis-caching.md2.0 KB
- 参考文档references/semantic-caching.md1.6 KB
03 SKILL.md 正文
Openrouter Caching Strategy
Overview
This skill shows how to implement caching layers for OpenRouter responses to reduce costs, lower latency, and handle repeated queries efficiently.
Prerequisites
- OpenRouter integration
- Cache storage (in-memory, Redis, or filesystem)
Instructions
- Generate cache keys: Hash the model ID, messages array, and key parameters (temperature, max_tokens) into a deterministic cache key
- Implement exact-match caching: Store responses keyed by the hash; return cached responses for identical requests (works best with
temperature: 0) - Add TTL-based expiration: Set cache entries to expire after a configurable period (e.g., 1 hour for factual queries, 5 minutes for dynamic content)
- Consider semantic caching: For fuzzy matching, use embedding similarity to find cached responses for semantically similar (but not identical) prompts
- Track cache hit rates: Log cache hits vs misses to measure cost savings and tune your caching strategy
Output
- Cache hit rate metrics showing percentage of requests served from cache
- Cost savings report comparing cached vs uncached request costs
- Latency improvement measurements (cached responses return in <5ms vs 500ms+ for API calls)
Error Handling
| Error | Cause | Fix |
|---|---|---|
| Stale cached responses | TTL too long for dynamic content | Reduce TTL or add cache invalidation triggers |
| Cache key collisions | Hash function not including all relevant parameters | Include model, messages, temperature, max_tokens, and tools in the key |
| Memory pressure | In-memory cache growing unbounded | Set max cache size with LRU eviction; use Redis for large caches |
See ${CLAUDE_SKILL_DIR}/references/errors.md for full error reference.
Examples
See ${CLAUDE_SKILL_DIR}/references/examples.md for runnable code samples.
Resources
04 同仓库更多 Skills
zustand-store-ts
Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state/action separation. Use when building React state management, creating global stores, or implementing reactive state patterns with Zustand.
zustand-store-creator
Zustand Store Creator - Auto-activating skill for Frontend Development. Triggers on: zustand store creator, zustand store creator Part of the Frontend Development skill category.
zero-trust-config-helper
Zero Trust Config Helper - Auto-activating skill for Security Advanced. Triggers on: zero trust config helper, zero trust config helper Part of the Security Advanced skill category.
zapier-integration-helper
Zapier Integration Helper - Auto-activating skill for Business Automation. Triggers on: zapier integration helper, zapier integration helper Part of the Business Automation skill category.
zai-cli
Execute z.AI CLI providing vision, search, reader, and GitHub exploration via CLI and MCP. Use when user needs image/video analysis, OCR, UI-to-code conversion, error diagnosis, real-time web search, web page to markdown extraction, or GitHub code exploration. Trigger with phrases like "analyze this image", "search the web for", "read this page", "explore this repo", or "use zai". Requires Z_AI_API_KEY.
yt-research
Research competitor YouTube channels, niches, and trending topics for your content strategy. Use this skill whenever the user says "research channels", "analyze competitors", "find trending topics", "niche analysis", "competitive research", "what are other creators doing", "scrape YouTube channels", or wants to understand the competitive landscape for a specific tool or topic area. Use when working with yt research. Trigger with 'yt', 'research'.