Last active
December 11, 2019 04:11
-
-
Save maapteh/895b0a50a1d5f8bca9089fe80b865127 to your computer and use it in GitHub Desktop.
caching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function (duration) { | |
| // cutted code | |
| return (req, res, next) => { | |
| // cutted code | |
| if (res.locals.ratelimited) { | |
| if (cacheContent) { | |
| res.setHeader(cacheKeyHeader, 'HIT'); | |
| res.status(200).send(cacheContent); | |
| return; | |
| } else { | |
| res.status(500).send(errorPage); | |
| return; | |
| } | |
| } | |
| if (!isMember && cacheContent) { | |
| res.setHeader(cacheKeyHeader, 'HIT'); | |
| res.status(200).send(cacheContent); | |
| return; | |
| } | |
| if (!cacheContent) { | |
| res.locals.sendResponse = res.send; | |
| res.setHeader(cacheKeyHeader, 'HIT'); | |
| res.send = (body) => { | |
| if (res.statusCode === 200) { | |
| memCache.put(key, body, duration * 1000); | |
| } | |
| res.locals.sendResponse(body); | |
| } | |
| } | |
| next(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment