0
0
Node.jsframework~10 mins

Why caching matters in Node.js - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to store a value in the cache object.

Node.js
cache['user'] = [1];
Drag options to blanks, or click blank then click option'
Anull
BfetchData()
C'John'
Dundefined
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function call instead of a value
Assigning undefined or null
2fill in blank
medium

Complete the code to check if the cache has a stored value for 'user'.

Node.js
if (cache.hasOwnProperty([1])) {
  console.log('Cache hit');
}
Drag options to blanks, or click blank then click option'
A'user'
B'cache'
C'data'
D'value'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking wrong key names
Using variables instead of string keys
3fill in blank
hard

Fix the error in the code to retrieve cached data safely.

Node.js
const userData = cache[1];
Drag options to blanks, or click blank then click option'
A['user']
B.get(
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation with a string key
Using parentheses like a function call
4fill in blank
hard

Fill both blanks to create a cache check and fallback fetch.

Node.js
const data = cache[1] [2] fetchFromDB();
Drag options to blanks, or click blank then click option'
A['item']
B||
C&&
D??
Attempts:
3 left
💡 Hint
Common Mistakes
Using && which requires both to be true
Using ?? which only checks for null or undefined
5fill in blank
hard

Fill all three blanks to implement a simple cache update after fetching data.

Node.js
if (!cache[1]) {
  cache[2] = fetchData();
}
return cache[3];
Drag options to blanks, or click blank then click option'
A['key']
D['data']
Attempts:
3 left
💡 Hint
Common Mistakes
Using different keys for check and assign
Forgetting to assign fetched data to cache