caching-patterns
SolidRedis 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
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
- 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
AI & Automation Solid
redis
Redis caching patterns, pub/sub, sessions, rate limiting, and data structures.
1,160 Updated today
a5c-ai AI & Automation Listed
caching-strategies
When improving read performance and reducing database load.
4 Updated 1 weeks ago
KraitDev AI & Automation Listed
010111-http-caching
Three-tier caching — browser, runtime, and distributed cache. Pipeline batching, atomic transactions, invalidation, and multi-language cache keys.
1 Updated yesterday
natuleadan API & Backend Listed
redis-patterns
Upstash Redis patterns for caching and rate limiting.
335 Updated today
aiskillstore AI & Automation Listed
caching-strategy
【缓存策略】设计和实现缓存方案,包含缓存选型、缓存模式、失效策略、缓存穿透/击穿/雪崩防护。 触发时机: - 用户要求"设计缓存方案"、"优化缓存" - 系统性能瓶颈在数据库查询 - 需要实现分布式缓存 支持 Redis/Memcached/本地缓存方案设计。
0 Updated 2 days ago
afine907