如何在Express-Node.js上主动缓存? [英] How to active caching on Express - Node.js?

查看:47
本文介绍了如何在Express-Node.js上主动缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在Express上激活缓存以快速提供页面?

how can i active the caching on Express to provide the pages quickly?

谢谢

推荐答案

您应仅在生产环境中启用缓存:

You should only enable caching in production:

app.configure('production', function(){
  var oneYear = 31557600000;
  app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
  app.use(express.errorHandler());
});

此外,使用CDN或Nginx托管静态文件可能更好.许多CDN都不那么贵,我什至在 http://www.coralcdn.org/<上找到了这个免费的CDN/a>感谢stackoverflow.com.根据此博客帖子Nginx甚至有memcached 使您的网站变得异常快速

Furthermore you are probably better of using CDN or Nginx to host static files. A lot of CDN's aren't that expensive and I even found this free CDN at http://www.coralcdn.org/ thanks to stackoverflow.com. According to this blog post Nginx even has memcached to make your site extremely fast

这篇关于如何在Express-Node.js上主动缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆