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

Enable/disable cache in configuration #62

Open
cotyhamilton opened this issue May 20, 2024 · 4 comments
Open

Enable/disable cache in configuration #62

cotyhamilton opened this issue May 20, 2024 · 4 comments

Comments

@cotyhamilton
Copy link

I'd like to control caching through config.

inspiration

this is how I control caching in development in with eta

const eta = new Eta({
    views: `${Deno.cwd()}/views/`,
    cache: !dev
});

example interface

a similar api in vento could allow for this

const env = vento({
  includes: `${Deno.cwd()}/views/`,
  cache: false // defaults to `true`
});
@cotyhamilton
Copy link
Author

I'm open to submitting a PR for this feature 🙂

@oscarotero
Copy link
Collaborator

This was suggested before here: #31

But the main problem is will make loops slower:

{{ for number of 100 }}
  {{ import "./show_number.vto" { number } }}
{{ /for }}

Without cache, the "show_number.vto" file is loaded and compiled 100 times.

The recommended way is to clear the cache manually, after any file change, with env.cache.clear();.
Is there any specific use case in which you need the cache disabled all the time?

@cotyhamilton
Copy link
Author

It's just a nice to have in dev.

Running that function manually will be the same effort as any other manual action: restart the server, add that function to a route and refresh a page, etc.

if (dev) {
  addEventListener("hmr", () => {
    env.cache.clear();
  });
}

This works okay but not when the vto files change lol. I'll see if there's a way to configure hmr or watch for files other than js.

It's a good point about the loops and performance

@oscarotero
Copy link
Collaborator

Maybe --watch=*.vto,*.js,*.ts or --unstable-hmr=*.vto,*.js,*.ts can do the job. I didn't try.

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

No branches or pull requests

2 participants