Skip to main content
100%

0-cache-second-try.js

✓ Published0🌍 Public
Aalessioalex
Last edited Nov 22, 2014
Created on Nov 22, 2014

This example demonstrates a caching pattern that wraps an asynchronous database lookup with a cache check, showing how repeated requests can bypass the original slow operation. The code defines an in-memory `users` object and a `getUserFromDb` function that simulates a 1–2 second delay using `setTimeout`. The `cachify` helper composes the original function with `getResultFromCache`, which returns the same user data synchronously via a zero-millisecond timeout. Two `console.time` calls compare the direct database hit against the cached call, visually timing the difference in the console.

AI-generated description

Similar vizzes