1

I've built an ExpressJS server that performs calculations on an array of objects. The array is placed in the body of the request (POST request) I've noticed that the first time I startup the server and send a request I receive the expected result from the calculation. Now when I send the exact same request to the server (without restarting the server), I receive a response much faster. I figure this is the case because ExpressJS may be caching requests/responses.

I've looked at the ExpressJS documentation for a detailed overview of how caching works in ExpressJS but can't find any. Can someone explain how caching works when an ExpressJS server receives a request and then receives that exact same request afterwards? Is there a way to disable caching completely?

SNV7
  • 2,403
  • 5
  • 23
  • 36
  • 1
    I'd suggest you first look in the network tab of the browser and see if perhaps the browser is caching the response (so your server is never asked again after the browser first gets the page). Your server can control browser caching settings based on the headers it applies to the original response. For example, the server can disable browser caching on any individual page. – jfriend00 Oct 28 '15 at 02:31
  • It could also be your browser that is doing the caching. – Tyler Oct 28 '15 at 03:08
  • I don't believe it is the browser. I've been stepping through the calculation process on the server and the response is already incorrect before a response is sent from the server. – SNV7 Oct 28 '15 at 03:12
  • So, you're saying that your server is code is doing something wrong, yet you show us no server code. Not much we can do to help you here. Please post the relevant code. – jfriend00 Oct 28 '15 at 04:56

1 Answers1

1

Express.js does not perform any caching by default. The effect you're seeing is probably due to the JIT (Just In Time compiler) in the Javascript V8 engine that runs your Node.js/Express.js code.

When starting your server, the Javascript code first gets compiled to machine code. In this step, the JIT will make some "good" optimizations to your code, but no "perfect" optimizations. At runtime (while your server is running) the JIT will further optimize your code using all kinds of nifty tricks. For example, code that gets executed more often ("hot code) will be more optimized than code that only rarely gets executed.

Some references for further information:

Community
  • 1
  • 1
xaviert
  • 4,476
  • 5
  • 25
  • 29