_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

27. 11. 2025 1 min read intermediate

Cache je nejefektivnější způsob zrychlení aplikace. Ale špatná cache invalidace je jeden z nejtěžších problémů v CS.

Strategies

  • Cache-aside: Aplikace čte/zapisuje cache explicitně
  • Write-through: Zápis do cache i DB současně
  • Write-behind: Zápis do cache, async do DB
  • Read-through: Cache automaticky načte z DB

HTTP Cache headers

Statické assety — dlouhý cache

Cache-Control: public, max-age=31536000, immutable

API response — krátký cache

Cache-Control: private, max-age=60

Validace s ETag

ETag: “abc123” If-None-Match: “abc123” # 304 Not Modified

Cache-aside pattern

async def get_product(product_id):

1. Check cache

cached = await redis.get(f”product:{product_id}”) if cached: return json.loads(cached)

2. Cache miss — fetch from DB

product = await db.products.find(product_id)

3. Store in cache

await redis.setex(f”product:{product_id}”, 3600, json.dumps(product)) return product

Key Takeaway

Cache-aside pro většinu use cases. HTTP cache headers pro CDN. Invalidace je těžší než se zdá — TTL je nejjednodušší.

cacheredisperformancecdn
Share:

CORE SYSTEMS tým

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