_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

Caching strategie — kde a jak cachovat

24. 10. 2025 1 min read intermediate

Architecture Intermediate

Caching strategie — kde a jak cachovat

CachingRedisPerformance 3 min read

Cache-aside, write-through, write-behind a invalidace cache. Kompletní průvodce.

Cache-Aside

async function getUser(id) {
    let user = await redis.get(\`user:\${id}\`);
    if (user) return JSON.parse(user);  // Cache hit
    user = await db.query('SELECT * FROM users WHERE id = $1', [id]);
    await redis.setex(\`user:\${id}\`, 3600, JSON.stringify(user));
    return user;
}

Strategies

  • Cache-Aside (Lazy Loading) — čti z cache, při miss načti z DB
  • Write-Through — zápis přes cache do DB, cache vždy aktuální
  • Write-Behind — zápis do cache, async do DB (rychlejší, rizikovější)

Invalidace

  • TTL — cache expiruje po čase
  • Event-driven — při změně dat publikujte invalidační event
  • Version-based — cache key obsahuje verzi

Summary

Cache-aside je nejbezpečnější start. Vždy mějte strategii pro invalidaci. Cache je optimalizace, ne datový zdroj.

Need Help with Implementation?

Our team has experience designing and implementing modern architectures. We’re happy to help.

Free Consultation

Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.