Closed marvinroger closed 6 years ago
This sounds like a good idea! Although, each piece of middleware would have to be refactored - at this stage that seems fine to make breaking changes.
Well, refactoring middleware should not be take too long. As you can see, it is only a matter of putting handler
's code in refresh
with some minors adjustments, and putting a generic handler
.
What about cached data on the disk? I was thinking of https://github.com/simonlast/node-persist, that stores data on the fs.
Right now, the data is cached in memory for
DEFAULT_CACHE_MSEC
and is refreshed upon a client request if the cached data expired. So, this client will receive its reponse after more time than if data was still cached.A solution to this would be to cache data at start without expiration date, and to refresh these datas using
setInterval
. Therefore, only the cached data needs to be served, so the response happens pretty instantly. Another advantage to this is that if the remote API is down, the cached data still exists, so there is always data available from the Me API.Here is how I would see the implementation, for example using the GitHub middleware:
To make this middleware functional, it is a matter of a dozen of lines in
lib/routes/me.js
.Data might event be cached on the disk, so that if Me API restarts for some reason and the remote API is down, cache would still be available.
Hope you get the idea, let me know what you think. ;)