liveBook · Manning

Eager caching

As explained in Vibe Engineering

Eager caching loads and retains cache contents before they are requested, commonly during application initialization.

Eager caching loads and retains cache contents before requests arrive, commonly during application initialization. It can make repeated lookups fast, but it shifts cost into startup and memory consumption. The central engineering question is not whether caching improves the hot path, but whether the cached dataset, access distribution, and object size justify loading everything in advance. section 7.4.1

Evaluate eager caching against these risks:

  • Memory waste increases when many cached entries are rarely used; complex objects make the cost more serious. section 7.4.1
  • Startup becomes slower because the cache is initialized when the application starts. section 7.4.1
  • Limit performance changes to the intended hot path so production impact remains measurable and understandable. section 7.4.1

Benchmarking the trade-off

A JMH comparison measured cached and file-based word lookup. The cached implementation reported 0.008 ms/op versus 63,631.677 ms/op for the baseline, while cache initialization was measured separately rather than treated as free.

How Vibe Engineering covers it

How deep it goes
Explains initialization, memory waste, startup cost, and scope control, but does not provide a lazy-cache implementation.
Examples
Compares cached and file-based word lookup using CachedWordsService and JMH measurements.
What it assumes
Assumes familiarity with application startup, caches, memory costs, hot paths, and performance benchmarks.
What you can do after
Evaluate caching decisions using dataset size, usage distribution, object complexity, startup cost, and benchmark results.
How it connects
Connects eager caching with lazy caching, hot-path optimization, application startup, and JMH benchmarking.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Vibe Engineering. The section links point to the parts of the book it draws on.