Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/apicache.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,16 @@ function ApiCache() {
return defaultDuration
}

this.getDuration = function(duration) {
/**
* Function that parses cache duration string to milliseconds
* Can be overriden with custom logic depending on request and response
* Sic! Use "appendKey" option to generate custom cache key for this case!
* @param {string|number} duration
* @param {Object} req Express request
* @param {Object} res Express response
* @returns {number} cache time in ms
*/
this.getDuration = function(duration, req, res) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmtrpro You're adding the params to the signature, but not using them in any way... am I missing something?

return parseDuration(duration, globalOptions.defaultDuration)
}

Expand All @@ -414,7 +423,6 @@ function ApiCache() {
}

this.middleware = function cache(strDuration, middlewareToggle, localOptions) {
var duration = instance.getDuration(strDuration)
var opt = {}

middlewareOptions.push({
Expand Down Expand Up @@ -591,6 +599,8 @@ function ApiCache() {
performanceArray.push(perf)

var cache = function(req, res, next) {
var duration = instance.getDuration(strDuration, req, res)

function bypass() {
debug('bypass detected, skipping cache.')
return next()
Expand Down