Skip to content

Commit

Permalink
feat(exclude): reorganize exclude option
Browse files Browse the repository at this point in the history
This option now support all possible exclusions:

 * query by default to true
 * paths as an array of regexp
  • Loading branch information
stephanebachelier committed Mar 5, 2016
1 parent b2b58fc commit c4cd458
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ function cache (config = {}) {
config.readCache = config.readCache || readCache
config.serialize = config.serialize || serialize

config.exclude = config.exclude || []
config.exclude = config.exclude || {}
config.exclude.query = config.exclude.query || true
config.exclude.paths = config.exclude.paths || []

if (config.log !== false) {
config.log = typeof config.log === 'function' ? config.log : console.log.bind(console)
Expand All @@ -32,13 +34,13 @@ function cache (config = {}) {
}

// do not cache request with query
if (req.url.match(/\?.*$/)) {
if (config.exclude.query && req.url.match(/\?.*$/)) {
return null
}

let found = false

config.exclude.forEach(regexp => {
config.exclude.paths.forEach(regexp => {
if (req.url.match(regexp)) {
found = true
return false
Expand Down

0 comments on commit c4cd458

Please sign in to comment.