Comparing version 1.0.12 to 1.0.13
@@ -152,3 +152,3 @@ /* jshint node:true, quotmark:false */ | ||
return new Promise(function (resolve, reject) { | ||
self.cache.get(src) | ||
var cached = (options.ignoreCache) ? Promise.reject() : self.cache.get(src) | ||
// in cache | ||
@@ -163,14 +163,16 @@ .then(function (result) { | ||
resolve(result.value); | ||
}) | ||
// not in cache | ||
.catch(function () { | ||
self.dataProvider.get(src, options) | ||
.then(function (result) { | ||
}); | ||
// not in cache or cache ignored | ||
cached.catch(function () { | ||
self.dataProvider.get(src, options) | ||
.then(function (result) { | ||
if (!options.ignoreCache) { | ||
self.setCacheResult(src, result); | ||
resolve(result.body); | ||
}) | ||
.catch(function (error) { | ||
resolve(self.handleError(src, error)); | ||
}); | ||
}); | ||
} | ||
resolve(result.body); | ||
}) | ||
.catch(function (error) { | ||
resolve(self.handleError(src, error)); | ||
}); | ||
}); | ||
}); | ||
@@ -177,0 +179,0 @@ }; |
{ | ||
"name": "nodesi", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "ESI: the good parts in node.js", | ||
@@ -5,0 +5,0 @@ "main": "esi.js", |
@@ -556,2 +556,37 @@ /* jshint node:true, quotmark:false */ | ||
it('should ignore cache for selected requests', function (done) { | ||
// given | ||
server.addListener('request', function (req, res) { | ||
res.writeHead(200, {'Content-Type': 'text/html'}); | ||
res.end('hello'); | ||
}); | ||
var html = '<esi:include src="/cacheme"></esi:include>'; | ||
// when | ||
var esi = new ESI({ | ||
baseUrl: 'http://localhost:' + port | ||
}); | ||
esi.cache.set('http://localhost:' + port + '/cacheme', { | ||
value: 'stuff', | ||
expiresIn: 1 | ||
}); | ||
var processed = esi.process(html, { | ||
ignoreCache: true | ||
}); | ||
// then | ||
processed.then(function (response) { | ||
assert.equal(response, 'hello'); | ||
return esi.cache.get('http://localhost:' + port + '/cacheme'); | ||
}).then(function (cached) { | ||
assert.equal(cached.value, 'stuff'); | ||
done(); | ||
}).catch(done); | ||
}); | ||
it('should fetch components recursively', function (done) { | ||
@@ -558,0 +593,0 @@ // given |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
966665
1049