简体   繁体   中英

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? 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. Can you suggest the best approach for this?

PS - I have some .md & .json files using which I generate the .html files and return. So, instead of doing this, I want to have some caching which will store this generated .html files. I'll update the cached content only when my .md & .json files are updated.

I've read about express-redis-cache, but how would this solution work with load balanced node servers?

It wouldn't be a problem because all your load balanced node servers would connect to the same Redis host, which is fine.

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

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. 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.

Having said that, if you are looking to cache .html files probably then look at CloudFront instead of a bespoke caching solution using Redis.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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