LouL
Deno12mo ago
Lou

How to build/cache deno program ahead of time

Hey folks! New Deno user here, really loving it so far!

I've built a service that involves a Worker. The Worker is reponsible for executing some provided code. The Worker is terminated after a timeout if it's taking too long. I have a problem that the Worker always takes too long on the first execution of the program – both right after it's been deployed, or locally when running the test suite. In subsequent executions it's as fast as you'd expect.

How can I cache the program ahead of time? I thought thats what
deno cache
does, as its help string says "Download and compile a module with all of its static dependencies and save them in the local cache, without running any code", but its docs link (https://docs.deno.com/go/cache) redirects to the docs for
deno install
, and running
deno cache
on my
src/main.ts
and
src/worker.ts
doesn't have any effect on the problem I'm having.

I don't really need or want to use
deno compile
as I'm not shipping a binary to run on other people's machines, and I'd like to continue using
deno serve
.

What's the "right" way to "build" the program ahead of time and use the build cache?

I'm using
deno serve
to run it in both development and production. The production service is deployed as a Docker container. The dockerfile is super simple, it looks like this:

FROM denoland/deno:alpine-2.2.3
USER deno
COPY ./my-app /apps/my-app
WORKDIR /apps/my-app
RUN deno install --frozen
EXPOSE 8000
CMD ["deno", "serve", "--cached-only", "--allow-env=NODE_ENV", "--allow-read=src/worker.ts", "src/main.ts"]


Additionally, it's not the Worker creation that's taking a long time, it seems to be posting the message and sending the message back that takes a long time.

The timeout in these cases is 100ms, and the Worker code isn't doing anything, it's basically sending back a message immediately.

Thanks in advance for your help!
Deno
Install and cache dependencies for your project
`deno install`
Was this page helpful?