Solution: Unify Cache Clients
Wrap in-memory and Redis-like cache clients behind a unified async interface.
We'll cover the following...
We'll cover the following...
Solution explanation
Lines 2–11: We define the in-memory cache client.
It stores data in a simple object.
The API is synchronous, using
setItem()andgetItem().It returns values directly, not promises.
Lines 14–31: We define a Redis-like asynchronous cache client.
Both
set()andget()methods return promises.Each simulates a short delay to mimic real network latency.
The structure mirrors a real async client, like
ioredisornode-redis.
Lines 34–36: The
CacheAdapterconstructor stores the provided client.