D
Deno

help

Looking for caching API Responses

Aaleyki8/9/2023
Hello there, I'm looking for a package/or examples to cache API responses for a fresh project which call a mongodb server. I already check Deno Cache API but it doesn't answer my problem. or I'm using it wrong way Thanks for your time πŸ™‚
Jjavi8/9/2023
You can use Deno KV for that. Something along the lines of
const kv = await Deno.openKv();

const { value } = await kv.get<{ date: Date, data: unknown }>(["cache"])

if (value && Date.now() - value.date.getTime() <= 60 * 60 * 1000) {
return value.data
}

const data = await (await fetch("/my/api")).json()

await kv.set(["cache"], { date: new Date(), data })

return data
const kv = await Deno.openKv();

const { value } = await kv.get<{ date: Date, data: unknown }>(["cache"])

if (value && Date.now() - value.date.getTime() <= 60 * 60 * 1000) {
return value.data
}

const data = await (await fetch("/my/api")).json()

await kv.set(["cache"], { date: new Date(), data })

return data
Aaleyki8/9/2023
Hello javi thx for your answer, will it work on Deno Deploy with read-only permission ?
Jjavi8/9/2023
Hello AlΓ©ki! No worries You need access to kv's beta for it to work on deploy
Aaleyki8/9/2023
Thanks a lot , I'll go work on that, have a good day ! πŸ‘‹
Jjavi8/9/2023
<:to_anime1_wave:965663270310658109>

Looking for more? Join the community!

Recommended Posts
Using ZeroMQ from NPMAnyone got fixed the same error as this issue? https://github.com/denoland/deno/issues/18345Trying to pass parameters to runtime from rustHi, I'm launching a deno runtime from my project's code. I'm trying to pass some dynamic json variconsole.log in a worker - capture or hide output?Running under `deno repl` with no permissions, this prints 'yee'. In a browser's dev tools it would Deno debugging configuration is missing?```json "deno.enable": true, "deno.unstable": true, "deno.enablePaths": ["./api"], "deno.docIs there a way to show permissions used on start up during runtime?For example: If I was to run an App with `permissions: --allow-net=${hostname}:${port}` is there a wrestrict path applied for import mapshi, is it possible to restrict importmap application to only specific path? the rationale is: - vscoBest way to pass backend data to SSR rendered view?Looking for the "proper" way to pass data to an SSR rendered view. My first idea is setting custom pImport mapHi I have this in deno.json: ``` "imports": { "./app.controller": "./app.controller.ts", ``` butWhat should I specify to pass a "char *" in Deno.dlopen?For example, this is how you would use it in Python: ```python import ctypes lib = ctypes.cdll.LoadOverride NPM package dependencyRelating to my question yesterday (https://canary.discord.com/channels/684898665143206084/1137532072VS Code's debugger terminates before finishedI notice that occasionally the debugger terminates at the middle of the running, or at least doesn'tI need some guidance regarding interprocess communication with DenoWhat are good cross-platform (Windows, Linux) options for interprocess communication / data sharing What is the Deno class?What is Deno in Deno.cwd() ? Can someone link me to documentation? Why doesn't the Deno class need tGetIP + Ctx from middleware to a route not passedHi, I have test to retrieve IP visitor Code taken from Discord is always returning "localhost" (whe