简体   繁体   English

将Express与NodeJS一起使用时-视图缓存如何工作?

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

Express API: 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? 在app.js中, view cache未在开发模块中明确设置,应该吗?

  2. How does this caching mechanism work; 这种缓存机制如何工作? is it analagous to memcache? 是否与记忆快取类似?

As you can see it from the source , view cache is enabled by default only on production environment. 源代码可以看到,默认情况下仅在production环境中启用了视图缓存。 If you don't need caching on development (or other environments) you can omit setting it explicitly. 如果不需要在development (或其他环境)上缓存,则可以省略显式设置。

How view caching works instead is pretty simple. 视图缓存的工作原理非常简单。 If enabled, express stores compiled template in process memory and renders the cached version. 如果启用,express将编译的模板存储在进程内存中,并呈现缓存的版本。 This way no temporary cache files are generated and the template is retrieved quickly from memory. 这样就不会生成临时缓存文件,并且可以从内存中快速检索模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM