liveBook · Manning

Refresh-ahead caching

As explained in Advanced Algorithms and Data Structures

Refresh-ahead is a caching policy that proactively refreshes frequently requested entries before they expire.

When a frequently requested cache entry expires, the next request can trigger a slow read from the database and a cache update. Refresh-ahead avoids that latency by acting before expiration. section 7.6

The policy identifies popular entries that are about to expire, then asynchronously reads their current values from the main source and updates the cache. Requests continue using the cached value instead of waiting for database access. section 7.6

Apply refresh-ahead when the workload and consistency model support it:

  • Prefer entries with high request frequency, because proactive work is most valuable when it prevents repeated cache misses. section 7.6
  • Accept slight staleness, as in eventually consistent systems where cached data may lag the database briefly. section 7.6
  • Compare the policy with Read-Through and Cache-Aside, and avoid choices that overload the database or main storage. section 7.6

Shopping-cart availability

A shopping cart can tolerate an entry being slightly out of sync for roughly 100 milliseconds or even a second. Refresh-ahead can update a popular entry in the background while serving the existing cached value. section 7.6

How Advanced Algorithms and Data Structures covers it

How deep it goes
Defines proactive asynchronous refresh and its consistency trade-off, but does not detail implementation algorithms or concurrency control.
Examples
Uses shopping-cart availability and brief tolerated staleness as a concrete example.
What it assumes
Assumes entries can become stale and expire, and accepts eventual-consistency windows between cache and database.
What you can do after
Operate/configure a cache policy that asynchronously refreshes popular entries before expiration.
How it connects
Connects cache expiration, eventual consistency, Read-Through, Cache-Aside, Write-Back, and Write-Around.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Advanced Algorithms and Data Structures. The section links point to the parts of the book it draws on.