Skip to main content

Practice · 2 of 2

Cache the expensive backend

CHALLENGE
Difficulty: advanced+25 XP

Implement class CachedApi wrapping an expensive backend (any object with .fetch(key)): - get(key) returns backend.fetch(key) at most ONCE per distinct key (memoize) - the backend's fetch counter (injected via Backend class in the test) must show exactly one call per distinct key, however many get calls repeat - invalidate(key) forces the next get(key) to re-fetch

Back to lesson: Practice: Project: Performance Rescue