Skip to content

Commit 68294ba

Browse files
authored
Merge pull request #1072 from strongloop/bug/remove-expired-items-before-executing-expire
Remove expired items before executing expire
2 parents 72200ce + 96cd8ff commit 68294ba

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ 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 CacheItem.set('expired-key', 'a-value', 1).delay(20)
40+
.then(function() { return CacheItem.expire('expired-key', 1000); })
41+
.then(
42+
function() { throw new Error('expire() should have failed'); },
43+
function(err) {
44+
err.message.should.match(/expired-key/);
45+
err.should.have.property('statusCode', 404);
46+
});
47+
});
48+
3849
it('returns error when key does not exist', function() {
3950
return CacheItem.expire('key-does-not-exist', 1).then(
4051
function() { throw new Error('expire() should have failed'); },

0 commit comments

Comments
 (0)