caching-patterns

Solid

Redis caching strategies, cache invalidation, write-through/write-behind, TTL management, and cache stampede protection.

AI & Automation 496 stars 41 forks Updated 1 months ago MIT

Install

View on GitHub

Quality Score: 86/100

Stars 20%
90
Recency 20%
75
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

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
2 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