Performance: Deno KV (built-in key-value store)
Deno KV affects data retrieval speed and storage efficiency in server-side applications, impacting response time and throughput.
const kv = await Deno.openKv(); const sessionData = await kv.get(['sessions', sessionId]); // use cached sessionData locally
const sessionData = await fetch('https://external-api.com/session'); // external call every request // then parse and use sessionData
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using Deno KV for local data fetch | 0 (server-side) | 0 | 0 | [OK] Good |
| Fetching data from external API each request | 0 (server-side) | 0 | 0 | [X] Bad |
set, so kv.set(["key"], value) is correct.kv.set(["key"], value) to save data. -> Option Akv.set(["key"], value) to save data. [OK]get method is asynchronous, so it must be awaited.const kv = await Deno.openKv(); await kv.set(["user", "name"], "Alice"); const result = await kv.get(["user", "name"]); console.log(result.value);
get method fetches the stored value, which is "Alice".const kv = await Deno.openKv();
await kv.set("session", "active");
const status = await kv.get(["session"]);
console.log(status.value);set method requires the key to be an array, but here it is a string "session".get method uses the key as an array ["session"], which is correct.const kv = await Deno.openKv();
const userId = 42;
const newPrefs = { theme: "dark" };
// Which code below is correct?
Pass the test and this pattern moves unknown