New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/cache middleware #80
Conversation
Codecov Report
@@ Coverage Diff @@
## master #80 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 10 11 +1
Lines 166 183 +17
Branches 37 38 +1
=====================================
+ Hits 166 183 +17
Continue to review full report at Codecov.
|
d724f85
to
b111514
Compare
Correct me if I wrong please. Looks like this is sort of in-memory cache, and in this case we can't really apply such middleware for lambda functions, because containers will have different cache and other problems. Lambda may not save this between executions. It's better to use some sort of redis or memcache in case of using lambda. |
@NPCRUS I believe @lmammino is intending to leverage container re-use where possible. |
@peterjcaulfield Thank you very much for this article, make sense! |
@NPCRUS, if you check the documentation here and the example you can see that the middleware is broadly configurable. You can provide your own functions to calculate cache ids, save items in the cache and get them from the cache. It should be relatively easy to write those functions to adopt a remote caching backend if you need that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff. Just have 1 minor comment
src/middlewares/cache.js
Outdated
return options.getValue(cacheKey) | ||
}) | ||
.then((cachedResponse) => { | ||
if (cachedResponse) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we change this with if (cachedResponse === undefined) {
? . That way we gonna avoid false negatives when cache is returning 0
, null
or empty string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point :)
…e/cache-middleware
Adds a caching middleware