Skip to content
Browse files

Add utility routes to access the server's cache and memory usage.

  • Loading branch information...
1 parent 98075ca commit 812a485ab83c63d99d3153350b05c6781747ddac @ericf committed Apr 28, 2012
Showing with 30 additions and 0 deletions.
  1. +30 −0 app.js
View
30 app.js
@@ -155,4 +155,34 @@ app.get('/photos/:id/', function (req, res) {
});
});
+app.get('/cache/', function (req, res) {
+ var caches = {};
+
+ ['Place', 'Photo', 'Photos'].forEach(function (model) {
+ var cache = Y.PNM[model].prototype.cache;
+
+ caches[model] = {
+ entries: cache.get('size'),
+ bytes : Buffer.byteLength(JSON.stringify(cache.get('entries')))
+ };
+ });
+
+ res.json(caches);
+});
+
+app.del('/cache/', function (req, res) {
+ ['Place', 'Photo', 'Photos'].forEach(function (model) {
+ Y.PNM[model].prototype.cache.flush();
+ });
+
+ res.send('Flushed caches.');
+});
+
+app.get('/stats/', function (req, res) {
+ res.json({
+ uptime: process.uptime(),
+ memory: process.memoryUsage()
+ })
+});
+
module.exports = app;

0 comments on commit 812a485

Please sign in to comment.
Something went wrong with that request. Please try again.