Merge pull request #1072 from strongloop/bug/remove-expired-items-before-executing-expire
Remove expired items before executing expire
This commit is contained in:
commit
68294babdb
|
@ -121,6 +121,8 @@ function(modelName, key, value, options, callback) {
|
||||||
|
|
||||||
KeyValueMemoryConnector.prototype.expire =
|
KeyValueMemoryConnector.prototype.expire =
|
||||||
function(modelName, key, ttl, options, callback) {
|
function(modelName, key, ttl, options, callback) {
|
||||||
|
this._removeIfExpired(modelName, key);
|
||||||
|
|
||||||
var store = this._getStoreForModel(modelName);
|
var store = this._getStoreForModel(modelName);
|
||||||
|
|
||||||
if (!(key in store)) {
|
if (!(key in store)) {
|
||||||
|
|
|
@ -35,6 +35,17 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
|
||||||
.then(function(value) { should.equal(value, null); });
|
.then(function(value) { should.equal(value, null); });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns error when expiring a key that has expired', function() {
|
||||||
|
return CacheItem.set('expired-key', 'a-value', 1).delay(20)
|
||||||
|
.then(function() { return CacheItem.expire('expired-key', 1000); })
|
||||||
|
.then(
|
||||||
|
function() { throw new Error('expire() should have failed'); },
|
||||||
|
function(err) {
|
||||||
|
err.message.should.match(/expired-key/);
|
||||||
|
err.should.have.property('statusCode', 404);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('returns error when key does not exist', function() {
|
it('returns error when key does not exist', function() {
|
||||||
return CacheItem.expire('key-does-not-exist', 1).then(
|
return CacheItem.expire('key-does-not-exist', 1).then(
|
||||||
function() { throw new Error('expire() should have failed'); },
|
function() { throw new Error('expire() should have failed'); },
|
||||||
|
|
Loading…
Reference in New Issue