caching-strategies

Multi-level caching, cache invalidation, L1/L2/L3 cache hierarchies, and cache coherence.

0motionguy/gicm1 installsApache-2.0Synced Aug 22

Works with

Claude CodeCursorCodex CLIGitHub CopilotGemini CLI
---
name: caching-strategies
description: Multi-level caching, cache invalidation, L1/L2/L3 cache hierarchies, and cache coherence.
license: Apache-2.0
---

# Caching Strategies & Hierarchies

> Multi-level caching, cache invalidation, L1/L2/L3 cache hierarchies, and cache coherence.

## Core Concepts

### Cache-Aside Pattern
Application loads data from main store and updates cache.

```typescript
async function getUser(id: string): Promise<User> {
  const cached = await cache.get(`user:${id}`);
  if (cached) return JSON.parse(cached);

  const user = await db.users.findById(id);
  await cache.set(`user:${id}`, JSON.stringify(user), 3600);
  return user;
}
```

### Write-Through Pattern
Application writes to both cache and store.

```typescript
async function updateUser(id: string, data: any): Promise<void> {
  await db.users.update(id, data);
  await cache.set(`user:${id}`, JSON.stringify(data));
}
```

### Write-Behind Pattern
Cache updates asynchronously flush to store.

```typescript
class WriteBehindCache {
  private writeQueue: Promise<void> = Promise.resolve();

  async set(key: string, value: any): Promise<void> {
    await cache.set(key, value);
    this.writeQueue = this.writeQueue.then(() =>
      db.set(key, value).catch(console.error)
    );
  }
}
```

### Multi-Tier Caching
L1 (in-process) -> L2 (Redis) -> L3 (DB).

```typescript
class MultiTierCache {
  async get(key: string): Promise<any> {
    // L1: In-process cache
    let value = this.l1Cache.get(key);
    if (value) return value;

    // L2: Redis
    value = await redis.get(key);
    if (value) {
      this.l1Cache.set(key, value);
      return value;
    }

    // L3: Database
    value = await db.get(key);
    if (value) {
      await redis.set(key, value, 300);
      this.l1Cache.set(key, value);
    }
    return value;
  }
}
```

## Best Practices

1. **TTL Strategy**: Different TTLs for different data
2. **Cache Invalidation**: Proper cleanup on updates
3. **Thundering Herd**: Use locks during cold cache
4. **Monitoring**: Track hit rates
5. **Size Limits**: Implement LRU eviction

## Related Skills

- Redis Advanced Patterns
- Data Consistency Patterns
- Performance Optimization

---

**Token Savings**: ~850 tokens | **Last Updated**: 2025-11-08 | **Installs**: 1345 | **Remixes**: 401

More Performance skills

seo-audit

coreyhaines31/marketingskills

When the user wants to audit, review, or diagnose SEO issues on their site. Also use when the user mentions "SEO audit," "technical SEO," "why am I not ranking," "SEO issues," "on-page SEO," "meta tags review," "SEO health check," "my traffic dropped," "lost rankings," "not showing up in Google," "site isn't ranking," "Google update hit me," "page speed," "core web vitals," "crawl errors," or "indexing issues." Use this even if the user just says something vague like "my SEO is bad" or "help with SEO" — start with an audit. For building pages at scale to target keywords, see programmatic-seo. For adding structured data, see schema. For AI search optimization, see ai-seo.

195.1k

competitor-profiling

coreyhaines31/marketingskills

When the user wants to research, profile, or analyze competitors from their URLs. Also use when the user mentions 'competitor profile,' 'competitor research,' 'competitor analysis,' 'profile this competitor,' 'analyze competitor,' 'competitive intelligence,' 'competitor deep dive,' 'who are my competitors,' 'competitor landscape,' 'competitor dossier,' 'competitive audit,' or 'research these competitors.' Input is a list of competitor URLs. Output is structured competitor profile markdown files. For creating comparison/alternative pages from profiles, see competitors. For sales-specific battle cards, see sales-enablement.

65.8k

prospecting

coreyhaines31/marketingskills

When the user wants to find, qualify, and build a list of prospects to reach out to — across B2B SaaS, general B2B, or local small businesses. Also use when the user mentions "prospecting," "build a prospect list," "find prospects," "find leads," "lead gen list," "find SaaS companies that," "find B2B companies," "find local businesses," "ICP-fit accounts," "who should we go after," "outbound list," "target account list," "find clients near me," "businesses without websites," "prospect research," "qualified leads," "find my first customers," "early adopters," "design partners," "beta users," or "who has this problem." Use this for the list-building and qualification phase. For writing the outbound copy after the list is built, see cold-email. For deep competitive research on specific accounts, see competitor-profiling.

42.1k

← All Performance skills

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY