cache.js 800 B

123456789101112131415161718192021222324252627282930
  1. var config = require("./config");
  2. var redis = require("redis").createClient();
  3. var fs = require("fs");
  4. var exp = {};
  5. // sets the timestamp for +uuid+ to now
  6. exp.update_timestamp = function(uuid) {
  7. console.log("cache: updating timestamp for " + uuid);
  8. var time = new Date().getTime();
  9. redis.hmset(uuid, "t", time);
  10. };
  11. // create the key +uuid+, store +hash+ and time
  12. exp.save_hash = function(uuid, hash) {
  13. console.log("cache: saving hash for " + uuid);
  14. var time = new Date().getTime();
  15. redis.hmset(uuid, "h", hash, "t", time);
  16. };
  17. // get a details object for +uuid+
  18. // {hash: "0123456789abcdef", time: 1414881524512}
  19. // null when uuid unkown
  20. exp.get_details = function(uuid, callback) {
  21. redis.hgetall(uuid, function(err, data) {
  22. callback(err, data);
  23. });
  24. };
  25. module.exports = exp;