Browse files

[fix] CodeStyle

[doc] Updated the documentation
  • Loading branch information...
1 parent 44f7351 commit b89a6ced12550643650f5d3ce11903c8dbe9da73 @3rd-Eden committed Mar 31, 2013
Showing with 132 additions and 17 deletions.
  1. +109 −0 README.md
  2. +10 −7 lib/rest.js
  3. +13 −10 test/middleware.test.js
View
109 README.md
@@ -370,6 +370,115 @@ your `versions.json` file:
require('versions').listen();
```
+## Rest API
+
+#### GET /flush
+
+Completely removes the internal cache. This does not flush cache-headers for the
+HTTP requests.
+
+Returns:
+
+```js
+{
+ flush: 'OK'
+}
+```
+
+#### GET /expire?key=<key>
+
+Removes the matched item(s) from the internal cache. It uses the value of
+`?key=key` to find and match it against request URLS in the cache.
+
+Returns:
+
+```js
+{
+ expire: 'OK',
+ expired: 1
+}
+```
+
+#### GET /inspect?key=<key>
+
+Finds the item in the cache and displays some information about it, like the
+total size of gzip, content-length etc.
+
+Returns:
+
+```js
+{
+ key: 'name of the key',
+ data: {
+ 'Content-Length': 0,
+ 'Content-Length Gzip': 0,
+ 'Content-Type': 'text/html',
+ 'Last-Modified': 'Sun, 31 Mar 2013 13:37:33 GMT'
+ }
+}
+```
+
+Or when a given key is not found:
+
+```js
+{ inspect: 'Failed to find the requested key file in cache' }
+```
+
+#### GET /keys
+
+Lists all items that are currently in the cache.
+
+Returns:
+
+```js
+{
+ keys: [
+ "versions:0.1.14#/css/jitsu.min.css",
+ "#/id:home/img/sprite.png",
+ "versions:0.1.14#/js/jitsu.min.js",
+ "#/id:home/img/nodepm.png",
+ "versions:0.1.14#/js/cortex.min.js",
+ "#/id:home/img/trusted.png",
+ "#/id:home/img/cloud.png",
+ "#/id:home/webfonts/ss-standard.woff",
+ "#/id:home/webfonts/ss-social-regular.woff",
+ "#/id:home/webfonts/ss-social-circle.woff",
+ "#/id:home/img/spinner.gif"
+ ]
+}
+```
+
+#### GET /version
+
+Get the current version of internal cache.
+
+Returns:
+
+```json
+{ versions: '0.0.0' }
+```
+
+#### POST/PUT /version
+
+Update the server to a new version number, if Redis sync is also the changes will
+also be synced with other instances.
+
+Returns:
+
+```js
+{ versions: '0.0.0' }
+```
+
+Or when no body is send:
+
+```js
+{ error: 'Invalid body' }
+```
+
+#### GET /metrics
+
+Returns a bunch of metrics.
+
## License
MIT
View
17 lib/rest.js
@@ -43,21 +43,24 @@ 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) {
+ var query = req.uri.query
+ , cache = this.cache
+ , matches = 0;
+
+ cache.forEach(function each(key) {
if(query && ~key.indexOf(query.key)) {
- _cache.remove(key);
+ cache.remove(key);
+ matches++;
}
});
-
+
this.metrics.incr('expire', { req: req, res: res });
- res.JSON({ expire: 'OK' });
+ res.JSON({ expire: 'OK', expired: matches });
},
/**
View
23 test/middleware.test.js
@@ -284,12 +284,12 @@ describe('version.layer() integration', function () {
.end(function (get) {
expect(get.statusCode).to.equal(404);
versions.set('force extensions', false);
-
+
versions.app.request()
.head('/id:home/')
.end(function (head) {
expect(head.statusCode).to.equal(200);
-
+
versions.app.request()
.head('/id:home/img/sprite.png')
.end(function (head) {
@@ -462,26 +462,29 @@ describe('version.layer() integration', function () {
});
});
});
-
- describe('/expire', function() {
+
+ describe('/expire', function () {
before(function(done) {
versions.app.request()
.get('/id:home/img/sprite.png')
- .end(function (res) { done(); });
- })
-
+ .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) {
+ .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;
-
+ expect(JSON.parse(res.body).expired).to.equal(1);
+
done();
});
});

0 comments on commit b89a6ce

Please sign in to comment.