Feature: Allow expiration to be set off of the express response object#109
Open
stemsmit wants to merge 2 commits intorv-kip:masterfrom
Open
Feature: Allow expiration to be set off of the express response object#109stemsmit wants to merge 2 commits intorv-kip:masterfrom
stemsmit wants to merge 2 commits intorv-kip:masterfrom
Conversation
This will allow setting res.express_redis_cache_expire to set the entry expiration
added the documentation for the new res.express_redis_cache_expire value
|
please merge |
|
came here for something else but if someone interested you could achieve this by wrapping the redis cache middleware: api.get(
'/endpoint',
/**
* Conditions to bypass the cache.
* @param {import('express').Request} req
* @param {import('express').Response} res
* @param {import('express').NextFunction} next
*/
async (req, res, next) => {
req.redisCacheTime = 3600; // 1 hour.
if (condition) {
req.redisCacheTime = 900; // 15 minutes.
}
if (anotherCondition) {
res.use_express_redis_cache = false; // disable redis cache completely
}
// note that those condition must be based on url parameters (query or params),
// otherwise (even if I personally won't recommend that, there is valid use case) you want to mutate the res.express_redis_cache_name options
next();
},
(req, res, next) =>
redisCache.route({
expire: {
'2xx': req.redisCacheTime,
'3xx': req.redisCacheTime,
'4xx': 10,
'5xx': 10,
xxx: 1,
},
})(req, res, next),
yourResponseCallback
); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I noticed this PR has been submitted before but no explanation as to why fandaa closed it. I believe this feature would be useful. The code snippet below(which has been added to the README.md in this PR) is an example of the added feature.
If any other information is needed please let me know.