Why this matters
- VaultCommerce's cart, catalog, and session layers use different patterns because they have different freshness and durability needs.
- Picking the wrong pattern causes double writes, lost updates, or caches that never invalidate.
- Interviews ask you to diagram cache-aside and defend when write-through is worth the latency tax.
Cache-aside (lazy loading)
The application owns cache logic — check cache, on miss load DB, populate cache.
public Product getProduct(String sku) {
String key = "product:" + sku;
Product cached = redis.get(key);
if (cached != null) return cached;
Product product = productRepo.findBySku(sku);
if (product != null) {
redis.setex(key, Duration.ofMinutes(10), product);
}
return product;
}
VaultCommerce uses cache-aside for product pages — simple, debuggable, and the database remains source of truth. Invalidation happens on catalog update events.
Read-through and write-through
| Aspect | Read-through | Write-through |
|---|---|---|
| Who loads on miss | Cache library | Application |
| Write path | App writes DB only | App writes cache; cache writes DB |
| Consistency | Cache always populated on read | Cache and DB updated together |
| VaultCommerce | Not used — prefer explicit control | Session tokens (short TTL) |
Who loads on miss
Read-throughCache libraryWrite-throughApplicationWrite path
Read-throughApp writes DB onlyWrite-throughApp writes cache; cache writes DBConsistency
Read-throughCache always populated on readWrite-throughCache and DB updated togetherVaultCommerce
Read-throughNot used — prefer explicit controlWrite-throughSession tokens (short TTL)
Write-through adds write latency because every update hits cache and database synchronously. VaultCommerce uses it only for session tokens where stale reads are unacceptable and objects are small.
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 3 sections
- Write-behind (write-back)
- VaultCommerce pattern map
- Invalidation strategies
Test yourself
Answer these before moving on — recall is what makes it stick.
- What caching strategies sit in front of a database? Cache-aside, read-through, write-through, write-behind.
- What caching strategies exist (cache-aside, read-through, write-through, write-back)? Which to choose when?
- How does Spring Boot caching work? Explain @EnableCaching, @Cacheable, @CachePut, and @CacheEvict.