cachingCaching strategies, invalidation, eviction policies, HTTP caching, distributed caching, and anti-patterns. Use when designing cache layers, choosing eviction policies, debugging stale data, or optimizing read-heavy workloads.
Install via ClawdBot CLI:
clawdbot install wpank/cachingA well-placed cache is the cheapest way to buy speed. A misplaced cache is the most expensive way to buy bugs.
| Strategy | How It Works | When to Use |
|----------|-------------|-------------|
| Cache-Aside (Lazy) | App checks cache → miss → reads DB → writes to cache | Default choice — general purpose |
| Read-Through | Cache fetches from DB on miss automatically | ORM-integrated caching, CDN origin fetch |
| Write-Through | Writes go to cache AND DB synchronously | Read-heavy with strong consistency |
| Write-Behind | Writes go to cache, async flush to DB | High write throughput, eventual consistency OK |
| Refresh-Ahead | Cache proactively refreshes before expiry | Predictable access patterns, low-latency critical |
Cache-Aside Flow:
App ──► Cache ──► HIT? ──► Return data
│
▼ MISS
Read DB ──► Store in Cache ──► Return data
| Method | Consistency | When to Use |
|--------|-------------|-------------|
| TTL-based | Eventual (up to TTL) | Simple data, acceptable staleness |
| Event-based | Strong (near real-time) | Inventory, profile updates |
| Version-based | Strong | Static assets, API responses, config |
| Tag-based | Strong | CMS content, category-based purging |
| Data Type | TTL | Rationale |
|-----------|-----|-----------|
| Static assets (CSS/JS/images) | 1 year + cache-busting hash | Immutable by filename |
| API config / feature flags | 30–60 seconds | Fast propagation needed |
| User profile data | 5–15 minutes | Tolerable staleness |
| Product catalog | 1–5 minutes | Balance freshness vs load |
| Session data | Match session timeout | Security requirement |
| Directive | Meaning |
|-----------|---------|
| max-age=N | Cache for N seconds |
| s-maxage=N | CDN/shared cache max age (overrides max-age) |
| no-cache | Must revalidate before using cached copy |
| no-store | Never cache anywhere |
| must-revalidate | Once stale, must revalidate |
| private | Only browser can cache, not CDN |
| public | Any cache can store |
| immutable | Content will never change (within max-age) |
| stale-while-revalidate=N | Serve stale for N seconds while fetching fresh |
# Immutable static assets (hashed filenames)
Cache-Control: public, max-age=31536000, immutable
# API response, CDN-cached, background refresh
Cache-Control: public, s-maxage=60, stale-while-revalidate=300
# Personalized data, browser-only
Cache-Control: private, max-age=0, must-revalidate
ETag: "abc123"
# Never cache (auth tokens, sensitive data)
Cache-Control: no-store
| Mechanism | Request Header | Response Header | How It Works |
|-----------|---------------|-----------------|-------------|
| ETag | If-None-Match: "abc" | ETag: "abc" | Hash-based — 304 if match |
| Last-Modified | If-Modified-Since: | Last-Modified: | Date-based — 304 if unchanged |
Prefer ETag over Last-Modified — ETags detect content changes regardless of timestamp granularity.
| Solution | Speed | Shared Across Processes | When to Use |
|----------|-------|------------------------|-------------|
| In-memory LRU | Fastest | No | Single-process, bounded memory, hot data |
| Redis | Sub-ms (network) | Yes | Production default — TTL, pub/sub, persistence |
| Memcached | Sub-ms (network) | Yes | Simple key-value at extreme scale |
| SQLite | Fast (disk) | No | Embedded apps, edge caching |
| Feature | Redis | Memcached |
|---------|-------|-----------|
| Data structures | Strings, hashes, lists, sets, sorted sets | Strings only |
| Persistence | AOF, RDB snapshots | None |
| Pub/Sub | Yes | No |
| Max value size | 512 MB | 1 MB |
| Verdict | Default choice | Pure cache at extreme scale |
| Concern | Solution |
|---------|----------|
| Partitioning | Consistent hashing — minimal reshuffling on node changes |
| Replication | Primary-replica — writes to primary, reads from replicas |
| Failover | Redis Sentinel or Cluster auto-failover |
Rule of thumb: 3 primaries + 3 replicas minimum for production Redis Cluster.
| Policy | How It Works | When to Use |
|--------|-------------|-------------|
| LRU | Evicts least recently accessed | Default — general purpose |
| LFU | Evicts least frequently accessed | Skewed popularity distributions |
| FIFO | Evicts oldest entry | Simple, time-ordered data |
| TTL | Evicts after fixed duration | Data with known freshness window |
Redis default isnoeviction. Setmaxmemory-policytoallkeys-lruorvolatile-lrufor production.
Browser Cache → CDN → Load Balancer → App Cache → DB Cache → Database
| Layer | What to Cache | Invalidation |
|-------|--------------|--------------|
| Browser | Static assets, API responses | Versioned URLs, Cache-Control |
| CDN | Static files, public API responses | Purge API, surrogate keys |
| Application | Computed results, DB queries, external API | Event-driven, TTL |
| Database | Query plans, buffer pool, materialized views | ANALYZE, manual refresh |
When a hot key expires, hundreds of requests simultaneously hit the database.
| Technique | How It Works |
|-----------|-------------|
| Mutex / Lock | First request locks, fetches, populates; others wait |
| Probabilistic early expiration | Random chance of refreshing before TTL |
| Request coalescing | Deduplicate in-flight requests for same key |
| Stale-while-revalidate | Serve stale, refresh asynchronously |
| Strategy | When to Use |
|----------|-------------|
| On-deploy warm-up | Predictable key set, latency-sensitive |
| Background job | Reports, dashboards, catalog data |
| Shadow traffic | Cache migration, new infrastructure |
| Priority-based | Limited warm-up time budget |
Cold start impact: A full cache flush can increase DB load 10–100x. Always warm gradually or use stale-while-revalidate.
| Metric | Healthy Range | Action if Unhealthy |
|--------|--------------|---------------------|
| Hit rate | > 90% | Low → cache too small, wrong TTL, bad key design |
| Eviction rate | Near 0 steady state | High → increase memory or tune policy |
| Latency (p99) | < 1ms (Redis) | High → network issue, large values, hot key |
| Memory usage | < 80% of max | Approaching max → scale up or tune eviction |
immutable Cache-Control — browsers will never re-fetchGenerated Mar 1, 2026
An online retailer uses cache-aside with Redis to store product details and inventory, reducing database load during flash sales. They implement TTL-based invalidation with a 5-minute TTL for catalog data and event-based invalidation for inventory updates to ensure strong consistency.
A social platform employs read-through caching with Redis to serve personalized user feeds, leveraging LFU eviction for skewed popularity. They use HTTP caching with ETags for API responses to minimize bandwidth and ensure fresh content delivery.
A trading platform uses write-through caching with in-memory LRU for real-time market data, ensuring strong consistency for read-heavy workloads. They implement cache stampede prevention with mutex locks to avoid database overload during high-frequency updates.
A hospital system utilizes write-behind caching with SQLite for patient records, allowing high write throughput with eventual consistency. They apply private Cache-Control directives for browser caching to secure sensitive data while maintaining fast access.
A streaming service leverages CDN caching with refresh-ahead strategies for video assets, using immutable Cache-Control headers for hashed files. They implement tag-based invalidation to purge content across distributed caches when updates occur.
A SaaS provider integrates caching to optimize multi-tenant applications, using Redis for shared data across processes to reduce latency and scale read-heavy workloads. This improves user experience and allows for tiered pricing based on performance features.
An e-commerce platform employs distributed caching with consistent hashing to handle high traffic during peak seasons, using cache layers from browser to database to speed up page loads. This increases conversion rates and reduces infrastructure costs.
An API service uses HTTP caching with ETags and Cache-Control directives to minimize server load and bandwidth usage for clients. They implement version-based invalidation for static assets, enabling scalable monetization through API call limits and premium caching tiers.
💬 Integration Tip
Start with cache-aside and Redis for production defaults, then layer in HTTP caching and eviction policies based on specific data access patterns to avoid overcomplication.
Automatically update Clawdbot and all installed skills once daily. Runs via cron, checks for updates, applies them, and messages the user with a summary of what changed.
Full desktop computer use for headless Linux servers. Xvfb + XFCE virtual desktop with xdotool automation. 17 actions (click, type, scroll, screenshot, drag,...
Essential Docker commands and workflows for container management, image operations, and debugging.
Tool discovery and shell one-liner reference for sysadmin, DevOps, and security tasks. AUTO-CONSULT this skill when the user is: troubleshooting network issues, debugging processes, analyzing logs, working with SSL/TLS, managing DNS, testing HTTP endpoints, auditing security, working with containers, writing shell scripts, or asks 'what tool should I use for X'. Source: github.com/trimstray/the-book-of-secret-knowledge
Deploy applications and manage projects with complete CLI reference. Commands for deployments, projects, domains, environment variables, and live documentation access.
Monitor topics of interest and proactively alert when important developments occur. Use when user wants automated monitoring of specific subjects (e.g., product releases, price changes, news topics, technology updates). Supports scheduled web searches, AI-powered importance scoring, smart alerts vs weekly digests, and memory-aware contextual summaries.