Closed wrapperup closed 8 months ago
Okay but I have two questions:
if (this.options.cache) {
this.cache.set(file, template);
}
Doing that, you don't need to check the cache in other places because it will be alwasy empty.
function fileChanged() {
env.cache.clear();
}
This allows to use the cache while the files doesn't change. Useful if you have imports inside a loop, like:
{{ for number of 100 }}
{{ import "./show_number.vto" { number } }}
{{ /for }}
Without cache, the "show_number.vto" file is loaded and compiled 100 times.
Clearing the cache is a nicer approach. I guess at some level this should be done in the integration, rather than here.
Perhaps instead there should be a split in the run
API, one is user facing (we can clear the cache there) and the internal one plugins/etc can use.
If not, I think documenting this trick would be great.
The run
split would make the code more complicated, because it should pass the option to load, runString
also use cache...
If clearing the cache works for you, I'd close this pull request. But feel free to open a new one if you want to contribute with the documentation!
Thanks!
This adds an option to disable the cache, useful if you want to iterate on templates in dev-time. The cache is still set (template internals still use them), but cache hits are ignored.