0
0
Expressframework~10 mins

In-memory caching with node-cache in Express - Interactive Code Practice

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

Complete the code to import the NodeCache library.

Express
const NodeCache = require('[1]');
Drag options to blanks, or click blank then click option'
Anode-cache
Bexpress
Ccache-node
Dmemory-cache
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' instead of 'node-cache'.
Mixing up package names like 'memory-cache'.
2fill in blank
medium

Complete the code to create a new cache instance.

Express
const cache = new NodeCache({ stdTTL: [1] });
Drag options to blanks, or click blank then click option'
A1000
B60
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting TTL to 0 disables expiration, which is not typical here.
Using a very large number like 1000 seconds without reason.
3fill in blank
hard

Fix the error in setting a cache value with key 'user' and value 'John'.

Express
cache.[1]('user', 'John');
Drag options to blanks, or click blank then click option'
Aget
Bput
Cadd
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'set' causes no data to be saved.
Using 'add' or 'put' which are not methods in node-cache.
4fill in blank
hard

Fill both blanks to retrieve a cached value and handle a cache miss.

Express
const value = cache.[1]('key');
if (value === [2]) {
  console.log('Cache miss');
}
Drag options to blanks, or click blank then click option'
Aget
Bnull
Cundefined
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for null instead of undefined causes missed cache misses.
Using 'set' instead of 'get' to retrieve data.
5fill in blank
hard

Fill all three blanks to create a cache, set a value, and retrieve it.

Express
const cache = new NodeCache({ stdTTL: [1] });
cache.[2]('color', 'blue');
const color = cache.[3]('color');
Drag options to blanks, or click blank then click option'
A120
Bset
Cget
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'delete' instead of 'get' to retrieve data.
Setting TTL to 0 disables expiration unintentionally.