liveBook · Manning

Eviction

As explained in Vibe Engineering

Cache eviction is the removal of cached entries according to a policy, such as elapsed inactivity time, to limit retained data.

Cache eviction removes stale entries so a cache can limit retained data instead of growing until memory usage becomes unsafe. Time-based eviction is useful when a lazily populated cache serves data that may remain unused, especially across larger dictionaries or multiple languages. section 7.4 section 7.4.1

Treat eviction as an operational decision rather than an arbitrary timeout:

  • Estimate an initial duration from the expected traffic pattern, service-level objectives, and request rate when production data is unavailable. section 7.4
  • Derive intervals between requests from logs, construct their statistical distribution, and choose a percentile such as the 90th or 99th as a candidate duration. section 7.4
  • Record cache hits, misses, and related statistics after deployment; increase the duration when the miss ratio is high. section 7.4
  • Preserve tracing and metrics, and prefer established cache implementations such as Google Guava, Caffeine, or Spring cache rather than expanding manual eviction code. section 7.4.1

A word-existence cache

A loading cache can use expire-after-access with a default eviction time of five minutes, record statistics, and call the existing word-existence method on a miss. The duration remains a tunable default rather than a permanent assumption. section 7.4

Listing 7.18 Constructing a word-exists cache
LoadingCache<String, Boolean> wordExistsCache = 
    CacheBuilder.newBuilder()
    .ticker(ticker)
    .expireAfterAccess(DEFAULT_EVICTION_TIME).recordStats() #A
    .build(
         new CacheLoader<String, Boolean>() {
           @Override
           public Boolean load(@Nullable String word) throws Exception {
       if (word == null)
             return false; #B
             }
        return checkIfWordExists(word); #C
           }
          });

Shows a loading cache combining access-based expiration, statistics recording, null handling, and miss-time loading. section 7.4

How Vibe Engineering covers it

How deep it goes
Explains percentile selection, production measurement, and miss-ratio tuning, but does not develop eviction internals.
Examples
Uses a word-existence cache with five-minute access expiration, statistics recording, request percentiles, and production miss-ratio monitoring.
What it assumes
Assumes familiarity with caching and request traffic, while explaining how to choose an initial duration when production measurements are unavailable.
What you can do after
Operate/configure a time-evicting cache and tune its duration using traffic distributions, cache statistics, and memory constraints.
How it connects
Connects cache eviction with lazy loading, cache hits, cache misses, memory usage, tracing, and caching libraries.

Also explained in

Compare how 3 books explain eviction →

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.