Skip to content

Commit

Permalink
Added route '/expire' to expire a specific key
Browse files Browse the repository at this point in the history
  • Loading branch information
eboskma committed Mar 29, 2013
1 parent d19fe8a commit c0d6c52
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/rest.js
Expand Up @@ -43,6 +43,22 @@ var routes = {

res.JSON({ flush: 'OK' });
},

/**
* Expire a specific item in the cache, specified by ?key=<keyname>
*/
'/expire': function expire(req, res, next) {
var query = req.uri.query;
var _cache = this.cache;
this.cache.forEach(function(key) {
if(query && ~key.indexOf(query.key)) {
_cache.remove(key);
}
});

this.metrics.incr('expire', { req: req, res: res });
res.JSON({ expire: 'OK' });
},

/**
* Inspects an item in the cache, use ?key=<keyname> to inspect the cache
Expand Down
24 changes: 24 additions & 0 deletions test/middleware.test.js
Expand Up @@ -462,6 +462,30 @@ describe('version.layer() integration', function () {
});
});
});

describe('/expire', function() {
before(function(done) {
versions.app.request()
.get('/id:home/img/sprite.png')
.end(function (res) { done(); });
})

it('removes a specific entry in the cache', function(done) {
expect(versions.cache.length).to.be.above(0);
var cacheLength = versions.cache.length;

versions.app.request()
.get('/expire?auth=foobar&key=' + escape('#/id:home/img/sprite.png'))
.end(function(res) {
expect(res.body).to.contain('OK');
expect(res.statusCode).to.equal(200);
expect(versions.cache.length).to.equal(cacheLength - 1);
expect(versions.cache.has('#/img/sprite.png')).to.be.false;

done();
});
});
});
});

describe('.layer(versioning)', function () {
Expand Down

0 comments on commit c0d6c52

Please sign in to comment.