Skip to content

Commit 95bc2e9

Browse files
committed
Remove expired item before executing expire
The expire feature is falsely returning 204 instead of 404 because it is not removing expired items before execution.
1 parent b156819 commit 95bc2e9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/connectors/kv-memory.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ function(modelName, key, value, options, callback) {
121121

122122
KeyValueMemoryConnector.prototype.expire =
123123
function(modelName, key, ttl, options, callback) {
124+
this._removeIfExpired(modelName, key);
125+
124126
var store = this._getStoreForModel(modelName);
125127

126128
if (!(key in store)) {

test/kvao/expire.suite.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ module.exports = function(dataSourceFactory, connectorCapabilities) {
3535
.then(function(value) { should.equal(value, null); });
3636
});
3737

38+
it('returns error when expiring a key that has expired', function() {
39+
return Promise.resolve(CacheItem.set('expired-key', 'a-value', 1))
40+
.delay(20)
41+
.then(function() { return CacheItem.expire('expired-key', 1000); })
42+
.then(
43+
function() { throw new Error('expire() should have failed'); },
44+
function(err) {
45+
err.message.should.match(/expired-key/);
46+
err.should.have.property('statusCode', 404);
47+
});
48+
});
49+
3850
it('returns error when key does not exist', function() {
3951
return CacheItem.expire('key-does-not-exist', 1).then(
4052
function() { throw new Error('expire() should have failed'); },

0 commit comments

Comments
 (0)