Skip to content

Commit 0975456

Browse files
Setting the cache timeout to zero now caches indefinitely, rather than expiring immediately
1 parent 72437c4 commit 0975456

5 files changed

Lines changed: 25 additions & 21 deletions

File tree

dist/ref-parser.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,14 @@ function download(protocol, u, options) {
658658
},{"./parse":4,"./promise":5,"./ref":7,"./util":10,"_process":108,"fs":98,"http":127,"https":105,"lodash/lang/isFunction":85,"ono":97,"url":137}],7:[function(require,module,exports){
659659
'use strict';
660660

661-
var util = require('./util'),
662-
url = require('url'),
663-
ono = require('ono'),
664-
_isObject = require('lodash/lang/isObject'),
665-
_isNumber = require('lodash/lang/isNumber'),
666-
_isString = require('lodash/lang/isString');
661+
var util = require('./util'),
662+
url = require('url'),
663+
ono = require('ono'),
664+
_isObject = require('lodash/lang/isObject'),
665+
_isNumber = require('lodash/lang/isNumber'),
666+
_isString = require('lodash/lang/isString'),
667+
escapedSlash = /~1/g,
668+
escapedTilde = /~0/g;
667669

668670
module.exports = $Ref;
669671

@@ -739,7 +741,7 @@ $Ref.prototype.setValue = function(value, options) {
739741

740742
// Extend the cache expiration
741743
var cacheDuration = options.cache[this.type];
742-
if (_isNumber(cacheDuration)) {
744+
if (_isNumber(cacheDuration) && cacheDuration > 0) {
743745
var expires = Date.now() + (cacheDuration * 1000);
744746
this.expires = new Date(expires);
745747
}
@@ -901,7 +903,7 @@ function parseJsonPointer(hash) {
901903

902904
// Decode each part, according to RFC 6901
903905
for (var i = 0; i < hash.length; i++) {
904-
hash[i] = hash[i].replace(/~1/g, '/').replace(/~0/g, '~');
906+
hash[i] = hash[i].replace(escapedSlash, '/').replace(escapedTilde, '~');
905907
}
906908

907909
if (hash[0] !== '') {

dist/ref-parser.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ref-parser.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ref-parser.min.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ref.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
'use strict';
22

3-
var util = require('./util'),
4-
url = require('url'),
5-
ono = require('ono'),
6-
_isObject = require('lodash/lang/isObject'),
7-
_isNumber = require('lodash/lang/isNumber'),
8-
_isString = require('lodash/lang/isString');
3+
var util = require('./util'),
4+
url = require('url'),
5+
ono = require('ono'),
6+
_isObject = require('lodash/lang/isObject'),
7+
_isNumber = require('lodash/lang/isNumber'),
8+
_isString = require('lodash/lang/isString'),
9+
escapedSlash = /~1/g,
10+
escapedTilde = /~0/g;
911

1012
module.exports = $Ref;
1113

@@ -81,7 +83,7 @@ $Ref.prototype.setValue = function(value, options) {
8183

8284
// Extend the cache expiration
8385
var cacheDuration = options.cache[this.type];
84-
if (_isNumber(cacheDuration)) {
86+
if (_isNumber(cacheDuration) && cacheDuration > 0) {
8587
var expires = Date.now() + (cacheDuration * 1000);
8688
this.expires = new Date(expires);
8789
}
@@ -243,7 +245,7 @@ function parseJsonPointer(hash) {
243245

244246
// Decode each part, according to RFC 6901
245247
for (var i = 0; i < hash.length; i++) {
246-
hash[i] = hash[i].replace(/~1/g, '/').replace(/~0/g, '~');
248+
hash[i] = hash[i].replace(escapedSlash, '/').replace(escapedTilde, '~');
247249
}
248250

249251
if (hash[0] !== '') {

0 commit comments

Comments
 (0)