Comparing version 0.3.0 to 0.3.1
@@ -65,3 +65,3 @@ module.exports = function Cache(options) { | ||
hits++; | ||
return cachedItems[key].value; | ||
return clone(cachedItems[key].value); | ||
} | ||
@@ -68,0 +68,0 @@ logger.log('Cache miss!'); |
@@ -7,3 +7,3 @@ { | ||
], | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"dependencies": { | ||
@@ -10,0 +10,0 @@ "clone": "0.2.x" |
@@ -71,2 +71,14 @@ var assert = require('assert'), | ||
it('should not allow the cached value to be modified after a get', function(done) { | ||
cache = new Cache(); | ||
cache.put('key', testValue); | ||
var value = cache.get('key'); | ||
value.fnord = 'hacky'; | ||
assert.deepEqual(cache.get('key'), testValue, 'The cached value should be equal to the test value'); | ||
done(); | ||
}); | ||
it('should get the cached value after the original expiration when using a sliding expiration', function(done) { | ||
@@ -219,2 +231,17 @@ | ||
it('should not allow the cached value to be modify after the insert', function(done) { | ||
var valueToCache = { some: 'object' }; | ||
cache = new Cache(); | ||
cache.put('key', testValue, valueToCache); | ||
valueToCache.some = 'fake'; | ||
var value = cache.get('key'); | ||
assert.notDeepEqual(value, valueToCache, 'the cached value should be the same as the value at the time of insert'); | ||
done(); | ||
}); | ||
it('cached value should be removed after expiration', function(done) { | ||
@@ -244,3 +271,2 @@ | ||
var value = cache.get('key'); | ||
console.log(value); | ||
assert.strictEqual(value, undefined, 'the cached value should be removed after expiration'); | ||
@@ -247,0 +273,0 @@ done(); |
19777
391