Build a Caching Proxy

Proxy pattern

Challenge 4 of Wrap & ExtendIntermediate~55 minFree

A slow service, and a stand-in that speaks its exact language. The Proxy pattern puts an object in front of the real one, sharing its interface so callers never know the difference, while it quietly adds superpowers. Build a proxy that delegates, then caches results, then defers construction until first use, then guards access, then invalidates stale entries. Same fetch(key) throughout; the real service never changes.

5 steps

  1. 1The Virtual Proxy
  2. 2Add Caching
  3. 3Lazy Initialization
  4. 4Protection Proxy
  5. 5Cache Invalidation
Start step 1