diff options
-rw-r--r-- | uos-live.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/uos-live.js b/uos-live.js index 629fd58..c89c6ae 100644 --- a/uos-live.js +++ b/uos-live.js @@ -3,6 +3,7 @@ window.UoSLive = {}; var busStopRequests = {}; + var busStopCache = {}; UoSLive.getBusStopURL = function(busStop) { var base = "http://bus.southampton.ac.uk/bus-stop/"; @@ -14,6 +15,12 @@ UoSLive.subscribeToBusStop = function(busStop, callback) { + if (busStop in busStopCache) { + var result = busStopCache[busStop]; + if (result.timeFetched > (Date.now() - 60000)) { + callback(result); + } + } var url = UoSLive.getBusStopURL(busStop); @@ -24,6 +31,9 @@ req.recurring = true; req.on('finished', function(code, result, headers) { + result.timeFetched = Date.now(); + busStopCache[busStop] = result; + callback(result); }); |