Permalink
Browse files

add updating of "all" var

  • Loading branch information...
1 parent 44c0cad commit 7fe8142f31410f4f42c8d36b60abbe7e3d9b41e3 @tj tj committed Oct 29, 2012
Showing with 18 additions and 4 deletions.
  1. +15 −2 app.js
  2. +3 −2 package.json
View
17 app.js
@@ -8,7 +8,8 @@ var express = require('express')
, all = fs.readFileSync(__dirname + '/components.json')
, redis = require('redis')
, db = redis.createClient()
- , app = module.exports = express();
+ , app = module.exports = express()
+ , ms = require('ms');
// middleware
@@ -95,4 +96,16 @@ app.get('/search/:query', function(req, res){
// perform search
query = wordKeys(query);
db.sunion(query, reply(res));
-});
+});
+
+/**
+ * Update all.
+ */
+
+setInterval(function(){
+ fs.readFile(__dirname + '/components.json', function(err, buf){
+ if (err) return console.log(err.stack);
+ console.log('updated all');
+ all = buf;
+ });
+}, ms('5m'));
View
5 package.json
@@ -6,7 +6,8 @@
"express": "3.x",
"redis": "0.8.1",
"superagent": "0.9.1",
- "component-wiki": "0.0.3"
+ "component-wiki": "0.0.3",
+ "ms": "~0.4.0"
},
"main": "app.js"
-}
+}

0 comments on commit 7fe8142

Please sign in to comment.