Skip to content

Commit

Permalink
add location cache to make sure we don't hit ipinfodb too much
Browse files Browse the repository at this point in the history
  • Loading branch information
mnutt committed Oct 28, 2010
1 parent f042527 commit 23257f4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/metrics/locations.js
@@ -1,5 +1,7 @@
var http = require('http');

var locationCache = {};

var LocationsMetric = {
name: 'Location',
initialData: {location: []},
Expand All @@ -17,6 +19,11 @@ var LocationsMetric = {
remoteAddress = view.env.ip;
}

if(locationCache[remoteAddress]) {
console.log('cache hit');
metric.data.location.push(locationCache[remoteAddress]);
}

client.on('error', function(exception) {
console.log("IP Lookup exception:");
console.log(JSON.stringify(exception, null, 2));
Expand Down Expand Up @@ -45,6 +52,8 @@ var LocationsMetric = {
city: city ? city[1] : "Unknown"
};

locationCache[remoteAddress] = location;

metric.data.location.push(location);
});
});
Expand Down

0 comments on commit 23257f4

Please sign in to comment.