Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using Express with NodeJS - How Does View Cache Work?

Express API:

view cache: Enables view template compilation caching, enabled in production by default

I have 2 questions:

  1. In app.js view cache isn't explicitly set in the development block, should it be?

  2. How does this caching mechanism work; is it analagous to memcache?

like image 754
Jack Avatar asked Sep 15 '14 23:09

Jack


People also ask

Does Express cache automatically?

Yes, express handles cache-control automatically. It's default value is set to true. And you can just handle it by increasing/decreasing it's maxAge property value.

How does Express work with node?

Express is a node js web application framework that provides broad features for building web and mobile applications. It is used to build a single page, multipage, and hybrid web application. It's a layer built on the top of the Node js that helps manage servers and routes.


1 Answers

As you can see it from the source, view cache is enabled by default only on production environment. If you don't need caching on development (or other environments) you can omit setting it explicitly.

How view caching works instead is pretty simple. If enabled, express stores compiled template in process memory and renders the cached version. This way no temporary cache files are generated and the template is retrieved quickly from memory.

like image 124
eymen Avatar answered Oct 05 '22 20:10

eymen