ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 384 forks source link

Production view cache #261

Open pi0neer opened 5 years ago

pi0neer commented 5 years ago

I'm confused with template caching, i've disabled it with app.disable('view cache');. In development everything is fine, but in production templates are still cached anyways. How can i disable it?

UziTech commented 5 years ago

https://github.com/ericf/express-handlebars#template-caching

Try passing cache: false as an option to the render call

pi0neer commented 5 years ago

It doesn't seem right in my opinion. I just wanna disable it for whole app at once, instead of passing a prop to each render call, also it's really uncomfortable in case of a big app. Documentation even says that is easiest way to control template/view caching and i would like to do it so.

mortezae commented 5 months ago

Hi there. I have two question regarding cache in production. Ask it here because found the question similar to myself.

  1. I don't want "page caching" (is it that so called "view cache"?), But I don't want templates read from disk by every request.
  2. I want compilation be done just once during app run time If possible. I mean templates to be half ready, to consume less cpu. I don't know whether it's the default behavior (some "implicit precompilation"?).
UziTech commented 5 months ago

Yes caching is default behavior

mortezae commented 5 months ago

Thanks for response. So please, how to avoid page cache while still taking advantage of this default caching behavior?

UziTech commented 5 months ago

app.disable('view cache');

mortezae commented 5 months ago

Yeah, but then It reads the template from disk for each request. This is a test with inotify:

morteza@pc1:~/accounting$  inotifywait views/home.hbs
Setting up watches.
Watches established.
views/home.hbs OPEN   <-- here we receive a new http request

P.S. Clarification: Readme has already been read and question was regarding production mode.

UziTech commented 4 months ago

See https://github.com/express-handlebars/express-handlebars?tab=readme-ov-file#template-caching