caching-patterns
SolidRedis caching strategies, cache invalidation, write-through/write-behind, TTL management, and cache stampede protection.
AI & Automation 531 stars
44 forks Updated 1 months ago MIT
Install
Quality Score: 86/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
Skill Content
# Caching Patterns
Redis-based caching strategies for reducing latency and database load.
## Cache Key Design
```typescript
// Namespace:entity:id format
const CacheKeys = {
market: (id: string) => `market:v1:${id}`,
marketList: (filters: string) => `market:list:${filters}`,
user: (id: string) => `user:v1:${id}`,
userMarkets: (userId: string, page: number) => `user:${userId}:markets:${page}`,
leaderboard: () => 'leaderboard:v1:global'
}
// Version prefix allows instant cache bust on schema change:
// bump v1 → v2 to invalidate all market keys without scanning
```
## Cache-Aside (Lazy Loading)
```typescript
import Redis from 'ioredis'
const redis = new Redis(process.env.REDIS_URL!)
const DEFAULT_TTL = 300 // 5 minutes
async function getOrSet<T>(
key: string,
loader: () => Promise<T>,
ttl = DEFAULT_TTL
): Promise<T> {
const cached = await redis.get(key)
if (cached) return JSON.parse(cached) as T
const value = await loader()
await redis.setex(key, ttl, JSON.stringify(value))
return value
}
// Usage
async function getMarket(id: string): Promise<Market> {
return getOrSet(
CacheKeys.market(id),
() => db.market.findUniqueOrThrow({ where: { id } }),
300
)
}
```
## Write-Through Pattern
```typescript
// Write to cache AND database together - cache is always fresh
async function updateMarket(id: string, data: UpdateMarketDto): Promise<Market> {
const updated = await db.market.update({ where: { id }, data })
// Synchronously up...
Details
- Author
- vibeeval
- Repository
- vibeeval/vibecosystem
- Created
- 6 months ago
- Last Updated
- 1 months ago
- Language
- C#
- License
- MIT
Integrates with
Similar Skills
Semantically similar based on skill content — not just same category
Code & Development Listed
cache
Cache. Redis, Memcached, Varnish, CDN, cache invalidation, TTL, write-through, cache stampede, thundering herd.
26 Updated 1 weeks ago
arbazkhan971 API & Backend Listed
redis-patterns
Use when using Redis in a Laravel app — caching strategies, atomic/distributed locks, rate limiting, stampede protection, pub/sub, pipelines, and key/TTL design beyond raw query tuning.
7 Updated 1 weeks ago
pekral Code & Development Solid
loom-caching
Caching strategies for performance optimization — cache-aside, write-through, write-behind, TTL policies, eviction, and stampede prevention.
54 Updated today
cosmix