Comparing version 0.4.0 to 0.4.1
20
index.js
@@ -28,7 +28,21 @@ var knox = require('knox'), | ||
var _get = function() { | ||
var _get = function(path, headers) { | ||
self.client.get(path, headers).on('response', function(res) { | ||
if (res.statusCode === 304) { | ||
return cache.get(path, callback); | ||
return cache.get(path, function(err, data) { | ||
if (err) return callback(err); | ||
if (!data) { | ||
// We need to bust the cache here. The data was cleared out of redis already, | ||
// but S3 think's it wasn't modified. | ||
cache.delete(path+'-date', function(err) { | ||
if (err) return callback(err); | ||
delete headers['If-Modified-Since']; | ||
self.get(path, headers, callback); | ||
}); | ||
} | ||
}); | ||
} | ||
if (res.statusCode != 200) { | ||
@@ -69,3 +83,3 @@ return callback(new Error('ERROR: status code = '+res.statusCode)); | ||
if (date) headers['If-Modified-Since'] = date; | ||
_get(); | ||
_get(path, headers); | ||
}); | ||
@@ -72,0 +86,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"description": "Simple S3 integration with a cache backed by Redis", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"repository": { | ||
@@ -17,3 +17,3 @@ "type": "git", | ||
"knox" : "*", | ||
"cacheit": "*", | ||
"cacheit": ">=0.3.0", | ||
"async": "*", | ||
@@ -20,0 +20,0 @@ "sax": "*" |
@@ -51,3 +51,47 @@ var S3 = require('../index'); | ||
it('can save and retrieve the original content again', function(done) { | ||
// Reset the default ttl to 10 sec | ||
s3.cache.default_ttl = 10; | ||
s3.put('/test/s3asy', { | ||
'Content-Type': 'text/plain', | ||
'Content-Length': original.length | ||
}, original, function(err) { | ||
assert.ok(!err); | ||
s3.get('/test/s3asy', function(err, data) { | ||
assert.ok(!err); | ||
assert.equal(data, original); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('can successfully bust the cache', function(done) { | ||
s3.cache.delete('/test/s3asy', function(err) { | ||
assert.ok(!err); | ||
// Data is no longer in cache | ||
s3.cache.get('/test/s3asy', function(err, data) { | ||
assert.ok(!err); | ||
assert.deepEqual(data, undefined); | ||
// Last modified date is still in the cache | ||
s3.cache.get('/test/s3asy-date', function(err, data) { | ||
assert.ok(!err); | ||
assert.ok(data); | ||
// Ensure the cache was busted by getting data back from S3 and not | ||
// undefined from the cache | ||
s3.get('test/s3asy', function(err, data) { | ||
assert.ok(!err); | ||
assert.deepEqual(data, original); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
8581
214
4
Updatedcacheit@>=0.3.0