cache-optimization

cache-optimization is a cursor rule for Cursor from brendadeeznuts1111/betting-brain-v3. It costs 0 tokens per session (4,330 once invoked), scanned A, original, MIT.

Project-specific rules for improving cache performance in Fantasy402, including key-value storage, expiration times, and cache metrics.

In plain words
What is it for?
Use them when changing Fantasy402 cache writes, expiration settings, cache keys, change detection, or cache-related metrics.
Why use it?
They help developers find cache operations and apply consistent patterns for storing data, detecting changes, and measuring cache use.

Cursor rule for Cursor

Install

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.

agentmods
npx agentmods add rules/brendadeeznuts1111/betting-brain-v3/cache-optimization
Clone the repo
git clone --depth 1 https://github.com/brendadeeznuts1111/betting-brain-v3

Made for: Cursor.

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

agentmods badge for cache-optimization

README.md
[![agentmods](https://agentmods.dev/badge/rules/brendadeeznuts1111/betting-brain-v3/cache-optimization.svg)](https://agentmods.dev/rules/brendadeeznuts1111/betting-brain-v3/cache-optimization)
Your own site
<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>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 4,330 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

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.

ModelPer sessionOnce 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

Measured 5d ago against content hash f3d845913a64, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

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'
.cursor/rules/cache-optimization.mdc · 594 lines

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

Read the full file on GitHub · 594 lines

Changes

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.

  1. 5d ago First seen · 594 lines · 0 tokens per session scan A f3d845913a64

Subscribe to this mod's changes

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.