...

/

Solution: Unify Cache Clients

Solution: Unify Cache Clients

Wrap in-memory and Redis-like cache clients behind a unified async interface.

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() and getItem().

    • It returns values directly, not promises.

  • Lines 14–31: We define a Redis-like asynchronous cache client.

    • Both set() and get() methods return promises.

    • Each simulates a short delay to mimic real network latency.

    • The structure mirrors a real async client, like ioredis or node-redis.

  • Lines 34–36: The CacheAdapter constructor stores the provided client.

...