Reputation: 1768
If I set maxAge when I called sendFile(), just like below:
res.sendFile('public/index.html', {maxAge: 100000})
Does this mean the file 'public/index.html' will cached in server's memory for 100 seconds? Or, This is just a message send to client side, and server side's does nothing with memory cache?
Upvotes: 5
Views: 5065
Reputation: 2579
maxAge
is a directive for the Cache-Control
header. In your case, this tells the client that index.html
will be considered 'fresh' for 100000ms, so it is unnecessary to ask the server again for that file until maxAge
has elapsed. The client keeps this file for the duration, it has nothing to do with server caching.
However, who caches what does depend on which way the directive is going.
As stated on MDN:
max-age= Specifies the maximum amount of time a resource will be considered fresh. Contrary to Expires, this directive is relative to the time of the request.
And
The Cache-Control general-header field is used to specify directives for caching mechanisms in both requests and responses. Caching directives are unidirectional, meaning that a given directive in a request is not implying that the same directive is to be given in the response.
Upvotes: 4