Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add rules/brendadeeznuts1111/betting-brain-v3/cache-optimizationgit clone --depth 1 https://github.com/brendadeeznuts1111/betting-brain-v3Wrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/rules/brendadeeznuts1111/betting-brain-v3/cache-optimization)<a href="https://agentmods.dev/rules/brendadeeznuts1111/betting-brain-v3/cache-optimization"><img src="https://agentmods.dev/badge/rules/brendadeeznuts1111/betting-brain-v3/cache-optimization.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00000 | $0.04330 |
| Opus 5 | $0.00000 | $0.02165 |
| Sonnet 5 | $0.00000 | $0.00866 |
| Haiku 4.5 | $0.00000 | $0.00433 |
Grade A, and why
cache-optimization scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Makes network callslowCapability
Not a fault in itself. Listed so you know the mod talks to something, and to what.
curl -s http://localhost:8787/api/f402/cache/metrics | jq '.summary' How it starts
The opening of the file, as written. The whole thing — 594 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Cache Optimization Patterns
Metadata:
- Status: ✅ Active (v1.0)
- Always Apply: false (Fantasy402-specific)
- Topics: #caching #performance #kv #optimization
- Last Updated: 2025-10-08
🔍 Code Searchability Patterns
Find cache-optimization Issues with ast-grep
# Find KV cache writes
ast-grep --pattern 'env.FANTASY_CACHE.put($KEY, $VALUE, { expirationTtl: $TTL })' src/
sg -p 'env.FANTASY_CACHE.put($KEY, $VALUE, { expirationTtl: $TTL })' src/
# Find hash-based change detection
ast-grep --pattern 'JSON.stringify($$$)' src/
sg -p 'JSON.stringify($$$)' src/
# Find cache metric increments
ast-grep --pattern 'incrementCacheMetric($$$)' src/
sg -p 'incrementCacheMetric($$$)' src/
# Find cache key patterns
ast-grep --pattern 'fantasy402:$$$:$$$' src/
sg -p 'fantasy402:' src/
cache-optimization Discovery Commands
sg search "FANTASY_CACHE.put" src/
sg search "expirationTtl" src/
sg search "incrementCacheMetric" src/
sg search "fantasy402:" src/
sg search "hash:" src/
Search Examples
# Find all KV cache operations
sg search 'env.FANTASY_CACHE.put($KEY, $VALUE, { expirationTtl: $TTL })' src/
# Find change detection patterns
sg search 'JSON.stringify($$$)' src/
# Find cache metrics
sg search 'incrementCacheMetric($$$)' src/
# Find cache keys
sg search 'fantasy402:' src/
Overview
Fantasy402 cache optimization patterns implemented in v1.0-cache-optimization achieving:
- 90%+ cache hit rate
- 93.3% D1 write reduction
- 1-hour TTL (safe during iteration, 24h in production)
Critical Performance Patterns
1. Multi-Key KV Caching (CRITICAL)
Why: Fantasy402 agent lists need multiple lookup patterns for different use cases.
// ✅ CORRECT: Multi-key caching with 3 lookup patterns
const agentOwner = agents[0]?.agentOwner;
const agentID = agents[0]?.agentID;
const cacheKeys = [
`fantasy402:agents:by-owner:${agentOwner}`, // Primary: lookup by owner
`fantasy402:agents:by-agent:${agentID}`, // Secondary: lookup by agent
`fantasy402:agents:latest:${agentOwner}` // Fallback: latest data
].filter(Boolean);
const cacheData = {
agents,
timestamp: new Date().toISOString(),
requestId
};
// Write to all keys in parallel
await Promise.all(
cacheKeys.map(key =>
env.FANTASY_CACHE!.put(key, JSON.stringify(cacheData), {
expirationTtl: 3600 // 1 hour (adjust to 86400 for 24h in production)
})
)
);
// ❌ WRONG: Single key only
await env.FANTASY_CACHE.put(
`fantasy402:agents:${agentOwner}`,
JSON.stringify(cacheData)
);
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 5d ago First seen · 594 lines · 0 tokens per session scan A f3d845913a64
cache-optimization is a cursor rule published in the GitHub repository brendadeeznuts1111/betting-brain-v3 (8 stars, last pushed 11mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 4,330 tokens. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other cursor rules, from other repositories
cache
为了方便开发者进行缓存操作的组件,它有利于改善项目的性能。它为我们提供了一个数据中心以便进行高效的数据访问。.
redis
This guide provides definitive, actionable best practices for using Redis effectively, focusing on data modeling, performance, security, and cluster-aware client usage to build robust and scalable applications.
database-access
資料庫存取模式(Supabase client/server 分工).
query-optimization
查詢優化、EXPLAIN、index 設計與 RLS 效能測量.
user-lifecycle
User lifecycle 規範(soft-delete / suspend / hard-delete 的 FK 策略與 guard pattern).
audit-schema
Supabase audit table schema 慣例(auditlogs).