agentsclimarketplace

Caching strategy

Skill kienbui1995/magic-powers/skills/caching-strategy

Use when implementing caching - Redis, CDN, HTTP cache headers, application-level memoization, or cache invalidation patternsFrom its SKILL.md

Install
npx -y skills add kienbui1995/magic-powers --skill caching-strategy

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

2.6 KB, as published. Nobody here has run it

Caching Strategy

Overview

Caching trades freshness for speed. The hard part isn't adding a cache — it's invalidating it correctly.

Core principle: Cache at the right layer, with the right TTL, and a clear invalidation strategy.

When to Use

  • Slow API responses that serve repeated data
  • High database load from identical queries
  • Static assets delivery optimization
  • Reducing third-party API calls

Cache Layers (top to bottom)

LayerTTLBest For
CDN (Cloudflare, CloudFront)Hours-daysStatic assets, public pages
HTTP cache (browser)Minutes-hoursAPI responses, images
Application cache (Redis/Memcached)Seconds-minutesDB query results, computed data
In-process (memoization)Request lifetimeExpensive computations within a request

Cache-Aside Pattern (most common)

1. Check cache for key
2. Cache hit → return cached value
3. Cache miss → fetch from source, store in cache, return

Invalidation Strategies

StrategyHowUse When
TTL expirySet expiration timeData can be slightly stale
Write-throughUpdate cache on every writeStrong consistency needed
Event-drivenInvalidate on data change eventMicroservices, async systems
Cache tagsTag entries, purge by tagRelated data changes together

HTTP Cache Headers

# Immutable static assets (hashed filenames)
Cache-Control: public, max-age=31536000, immutable

# API responses (revalidate)
Cache-Control: private, max-age=0, must-revalidate
ETag: "abc123"

# No caching
Cache-Control: no-store

Anti-Patterns

PatternProblem
Cache everythingStale data bugs, memory waste
No TTLCache grows forever
Cache without invalidation planStale data served indefinitely
Caching user-specific data in shared cacheData leaks between users
Cache stampedeAll caches expire simultaneously → DB overload

Redis Quick Reference

SET user:123 '{"name":"..."}' EX 300    # 5 min TTL
GET user:123
DEL user:123                              # Invalidate

Integration

  • magic-powers:performance-optimization — identify what to cache via profiling
  • magic-powers:infrastructure-review — review cache infrastructure
  • magic-powers:database-optimization — reduce DB load with query caching

Keep looking

Skills are one crate of 626,194. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.