Skip to main content

Practice ยท 2 of 2

Cache the expensive backend

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

Difficulty: advanced

Back to lesson: Practice: Project: Performance Rescue