'nginx can return the cache without invoke the node code?

I have nodejs application and /foo/123 endpoint that access to database to return the data.

router.get('/foo/123', (req, res) => {
 const data = getData();
 res.json({ data });
});

I want to cache this url for 30 minutes. everyone who invoke the url will get the results from the cache.

I know I can do it with redis to store the data and return the results. I also know I can set 304 header.

I was thinking to solve it with nginx. using nginx cache to return the data from the url.

My question is does nginx support cache in this way? I mean nginx will stop the request and return the results form the cache without invoking the node code

The user can make a request from the browser (ajax) and can do the request using curl command.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source