Thursday 31 October 2019

Does Node cache/memoize function calls?

Long story short-ish: I have a Node project, part of which exposes an endpoint to get a list of timezones with their UTC offsets at that precise moment. In the UK (where we're based), before 01:00 UTC on 27 October (when the UK leaves British Summer Time), the endpoint should return '(GMT+01:00) London', and after, it should return '(GMT+00:00) London'.The problem is that if I start the process before 01:00Z 27/10 and then call the endpoint after, it still returns '(GMT+01:00) London'. I simulate this by manually changing the system time.The data is generated by a function call that calls a formatting library that wraps Moment Timezone to generate the data. IIRC, unless its overridden, Moment will assume that the time you want is the current system time. So why, when I hit the endpoint after 01:00Z 27/10, does it behave as though it's before 01:00Z 27/10?A possibly related tangent: I inserted a console.log() in the function call to check the arguments and default values. I expect it to output whenever I hit the endpoint. In reality, it outputs to console five times as soon as I start the process, and then never again, no matter how many times I hit the endpoint.So the question is: is Node implicitly memoizing this function call, somehow?I understand this is an odd one, but if anyone has any experience of this or something like this, I'd be interested to know!

Submitted October 31, 2019 at 11:24AM by jl3b

No comments:

Post a Comment