A simple caching strategy for Node REST APIs, Part 1

Vignesh M on March 03, 2019

Hello World, this is the beginning of 2 Part Series on "How to make your REST APIs blazing fast 🚀". These are from my personal experiences and from... [Read Full]
markdown guide

It seems that you're using URL as cache key, right? Things to be considered:

  • are the URL-s public? I.e circumstances changes when the URL-s are behind authentication because then you cannot send back the same responses to all users etc.
  • do all the parameters come in via URL? Are there any headers or anything that may differ between requests? Should these be considered?

What's your cache backend?


Both of these considerations depend upon one's own project and what routes they want to cache. This example works best for data that only dependents on the URL and not any context like current user.


Can you explain the processQuery, responseHandler fuction for me.


Hey, processQuery & responseHandler are not anything related to caching or have anything to do with this artcle. They are just examples of common middlewares.

In our app, processQuery transforms some of our url query params, does some checks if they are valid.

responseHandler just converts the response data to json and returns a 200 status.
This may not be everyone's usecase.


Thank you. Do you still have this tutorial. i don't see it on your github


function getUrlFromRequest(req) {
const url = req.protocol + '://' + req.headers.host + req.originalUrl
return url

becasue of req.protocol in key the cache is not effective as can be :)

code of conduct - report abuse