Skip to content

Commit

Permalink
[api] Added cap for amount of local records which can be stored.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marak committed Jan 1, 2012
1 parent 52ca8fc commit 9e52546
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/hnet.js
Expand Up @@ -34,6 +34,9 @@ var Hnet = exports.Hnet = function (options) {
// Default to not resolviing circular data sets // Default to not resolviing circular data sets
self.ttl = options.ttl || -1; self.ttl = options.ttl || -1;


// Default amount of items we will allow to be stored in self.store
// TODO: size limit should be based on array size as bytes, not array size as elements.
self.MAXRECORDS = 100;


// //
// TODO: upgrade EE2 to version that has "**" // TODO: upgrade EE2 to version that has "**"
Expand Down Expand Up @@ -148,6 +151,13 @@ Hnet.prototype.parseDocument = function (node, doc, options) {
}); });
} }
doc.forEach(function(record){ doc.forEach(function(record){
//
// Determine if we've reached the capped size, if so, shift off some records,
// we dont need them
//
if(self.store.length >= self.MAXRECORDS) {
self.store.shift();
}
self.store.push(record); self.store.push(record);
}); });
} }
Expand Down

0 comments on commit 9e52546

Please sign in to comment.