Skip to content

Commit

Permalink
Release 0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanebachelier committed Jul 27, 2016
1 parent 39cabfb commit 0d9ff01
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "superapi-cache",
"version": "0.11.2",
"version": "0.12.0",
"homepage": "https://github.com/stephanebachelier/superapi-cache",
"authors": [
"Stéphane Bachelier <[email protected]>"
Expand Down
9 changes: 6 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ function cache() {
config.log = typeof config.log === 'function' ? config.log : console.log.bind(console);
}

return function (req, next, service) {
return function (req, next) {
var service = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];

if ((0, _exclude2.default)(req, service, config.exclude)) {
return null;
}

var uuid = key(req);
var options = service.cache || {};

// clear cache if method different from GET.
// We should exclude HEAD
Expand Down Expand Up @@ -77,10 +80,10 @@ function cache() {
}

var expiration = config.maxAge === 0 ? 0 : Date.now() + config.maxAge;
var hasServiceExpiration = service.use !== undefined && service.use.cache !== undefined && service.use.cache.expiration !== undefined;
var hasServiceExpiration = options.expiration !== undefined;

if (hasServiceExpiration) {
expiration = Date.now() + service.use.cache.expiration;
expiration = Date.now() + options.expiration;
config.log('override expiration to use ' + expiration);
}

Expand Down
9 changes: 6 additions & 3 deletions dist/umd/superapi-cache.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/umd/superapi-cache.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/umd/superapi-cache.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/umd/superapi-cache.min.js.map

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ function cache (config = {}) {
config.log = typeof config.log === 'function' ? config.log : console.log.bind(console)
}

return (req, next, service) => {
return (req, next, service = {}) => {
if (exclude(req, service, config.exclude)) {
return null
}

const uuid = key(req)
const options = service.cache || {}

// clear cache if method different from GET.
// We should exclude HEAD
Expand Down Expand Up @@ -60,12 +61,10 @@ function cache (config = {}) {

let expiration = config.maxAge === 0 ? 0 : Date.now() + config.maxAge
const hasServiceExpiration =
service.use !== undefined &&
service.use.cache !== undefined &&
service.use.cache.expiration !== undefined
options.expiration !== undefined

if (hasServiceExpiration) {
expiration = Date.now() + service.use.cache.expiration
expiration = Date.now() + options.expiration
config.log('override expiration to use ' + expiration)
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "superapi-cache",
"version": "0.11.2",
"version": "0.12.0",
"description": "Caching module for superapi",
"homepage": "https://github.com/stephanebachelier/superapi-cache",
"author": {
Expand Down

0 comments on commit 0d9ff01

Please sign in to comment.