ventojs / vento

🌬 A template engine for Deno & Node
https://vento.js.org/
MIT License
212 stars 12 forks source link

Enable/disable cache in configuration #62

Open cotyhamilton opened 6 months ago

cotyhamilton commented 6 months ago

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 commented 6 months ago

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

oscarotero commented 6 months ago

This was suggested before here: https://github.com/ventojs/vento/pull/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 commented 6 months ago

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 commented 6 months ago

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