Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support deno run --no-cache flag or { cache: false } import option to prevent caching of imports #13754

Closed
mimbrown opened this issue Feb 23, 2022 · 7 comments
Labels

Comments

@mimbrown
Copy link

Feature Request

I would like to be able to prevent Deno from caching imports on certain runs.

Use Case

I want to build a tool that supports importing many different kinds of files, such as .vue and .svelte files, in a server-side dev environment (similar to the vite.ssrLoadModule function). I know of no good way to transform/compile a local import on the fly, so my solution is to use a local server and import the file using the localhost url. This works, except Deno detects those imports as remote, not local, so it caches them. I don't want those files cached, but I can't find any way to prevent it.

Proposed API

I think ideally I would like to be able to disable caching on a per-import basis. This could be an extra flag on import options, maybe in a special deno section:

import('http://localhost:8000/index.svelte', { deno: { cache: false } });

An alternative would be to support a --no-cache flag:

deno run --no-cache ...
@lucsoft
Copy link

lucsoft commented Feb 25, 2022

its called --reload and its already a thing

@mimbrown
Copy link
Author

its called --reload and its already a thing

--reload is different. It tells Deno to bypass checking the cache for the requested import, but Deno still caches the requested code. I want a flag to tell Deno to bypass the cache entirely. Don't check it, don't add my imported code to it. Just skip it. I don't want a bunch of localhost dev imports cluttering up my cache.

@ejsmith
Copy link

ejsmith commented Feb 28, 2022

I think you are looking for this: #1739

@stale
Copy link

stale bot commented Apr 29, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 29, 2022
@stale stale bot closed this as completed May 31, 2022
@ralyodio
Copy link

ralyodio commented Oct 2, 2023

why was this closed?

@asyncanup
Copy link

yes, still need this

how about letting remote urls specifying caching behavior in their response with http cache headers?

@bastump987
Copy link

bastump987 commented Jan 24, 2024

Agreed, this would be a great thing to have. I am also importing local modules over HTTP (for the purposes of a plugin/module-federation-type architecture) and would really like to have these modules not cached.

You can sort of work around caching imports by adding a query param to your dynamic import that contains a random number (saw this on a GitHub issue somewhere but forget where, sorry for no credit):

const location = new URL('http://localhost:8080/myRemoteModule.ts');
location.searchParams.append('denoAntiCache', Math.random().toString());

The issue is that any imports required by the module that you just loaded over the network can still be served from Deno's cache... So the above workaround is only useful for modules that have no dependencies.

It would completely solve the issue for me if Deno's caching behavior could be controlled by the presence of the Cache-Control header.

Ideally, I could have the server serving my local modules set Cache-Control: no-cache on all its responses. This would remove the need for me to use the query param workaround and also prevent caching the items that I don't directly import().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants