简体   繁体   English

在Node JS中实现服务器端缓存的最佳方法

[英]Best way to implement server side cache in Node JS

I'm trying to implement the server-side cache in Node JS, I've read about express-redis-cache , but how would this solution work with load balanced node servers? 我正在尝试在Node JS中实现服务器端缓存,我已经阅读了有关express-redis-cache ,但是这个解决方案如何与负载均衡的节点服务器一起工作? I might use something like AWS Redis Service, but it loses the whole purpose of using Redis on some external server as it increases latency. 我可能会使用类似AWS Redis Service的东西,但它会失去在某些外部服务器上使用Redis的全部目的,因为它会增加延迟。 Can you suggest the best approach for this? 你能为此建议最好的方法吗?

PS - I have some .md & .json files using which I generate the .html files and return. PS - 我有一些.md.json文件,用它们生成.html文件并返回。 So, instead of doing this, I want to have some caching which will store this generated .html files. 因此,我希望有一些缓存来存储这些生成的.html文件,而不是这样做。 I'll update the cached content only when my .md & .json files are updated. 只有当我的.md.json文件更新时,我才会更新缓存的内容。

I've read about express-redis-cache, but how would this solution work with load balanced node servers? 我读过有关express-redis-cache的信息,但这个解决方案如何与负载均衡的节点服务器配合使用?

It wouldn't be a problem because all your load balanced node servers would connect to the same Redis host, which is fine. 这不会是一个问题,因为所有负载均衡的节点服务器都将连接到同一个Redis主机,这很好。

I might use something like AWS Redis Service, but it loses the whole purpose of using Redis on some external server as it increases latency 我可能会使用类似AWS Redis Service的东西,但它会失去在某些外部服务器上使用Redis的全部目的,因为它会增加延迟

It depends how you architect your app. 这取决于您如何构建您的应用程序。 If you are fully hosted on AWS, Elasticache is designed for this, latency would be minimal as connection will be within the VPC which is fast. 如果您完全托管在AWS上,Elasticache就是为此而设计的,延迟会很小,因为连接将在VPC内快速完成。 If you need to connect to elasticache from a client on premise, you still have options: VPN (not ideal) or DirectConnect which would be much faster than a VPN. 如果您需要从内部客户端连接到elasticache,您仍然可以选择:VPN(不理想)或DirectConnect,它比VPN快得多。

Having said that, if you are looking to cache .html files probably then look at CloudFront instead of a bespoke caching solution using Redis. 话虽如此,如果您希望缓存.html文件,那么可能会使用Redis查看CloudFront而不是定制的缓存解决方案。

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

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