blocks: add configurable option for caches
This commit is contained in:
parent
b446f6733c
commit
4e54d195b9
@ -8,13 +8,13 @@ var BN = bitcore.crypto.BN;
|
|||||||
var LRU = require('lru-cache');
|
var LRU = require('lru-cache');
|
||||||
|
|
||||||
|
|
||||||
function BlockController(node) {
|
function BlockController(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.node = node;
|
this.node = options.node;
|
||||||
|
|
||||||
this.blockSummaryCache = LRU(1000000);
|
this.blockSummaryCache = LRU(options.blockSummaryCacheSize || BlockController.DEFAULT_BLOCKSUMMARY_CACHE_SIZE);
|
||||||
this.blockCacheConfirmations = 6;
|
this.blockCacheConfirmations = 6;
|
||||||
this.blockCache = LRU(1000);
|
this.blockCache = LRU(options.blockCacheSize || BlockController.DEFAULT_BLOCK_CACHE_SIZE);
|
||||||
|
|
||||||
this.poolStrings = {};
|
this.poolStrings = {};
|
||||||
pools.forEach(function(pool) {
|
pools.forEach(function(pool) {
|
||||||
@ -29,6 +29,9 @@ function BlockController(node) {
|
|||||||
|
|
||||||
var BLOCK_LIMIT = 200;
|
var BLOCK_LIMIT = 200;
|
||||||
|
|
||||||
|
BlockController.DEFAULT_BLOCKSUMMARY_CACHE_SIZE = 1000000;
|
||||||
|
BlockController.DEFAULT_BLOCK_CACHE_SIZE = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find block by hash ...
|
* Find block by hash ...
|
||||||
*/
|
*/
|
||||||
|
|||||||
10
lib/index.js
10
lib/index.js
@ -46,6 +46,9 @@ var InsightAPI = function(options) {
|
|||||||
this.cacheShortSeconds = options.cacheShortSeconds;
|
this.cacheShortSeconds = options.cacheShortSeconds;
|
||||||
this.cacheLongSeconds = options.cacheLongSeconds;
|
this.cacheLongSeconds = options.cacheLongSeconds;
|
||||||
|
|
||||||
|
this.blockSummaryCacheSize = options.blockSummaryCacheSize || BlockController.DEFAULT_BLOCKSUMMARY_CACHE_SIZE;
|
||||||
|
this.blockCacheSize = options.blockCacheSize || BlockController.DEFAULT_BLOCK_CACHE_SIZE;
|
||||||
|
|
||||||
if (!_.isUndefined(options.routePrefix)) {
|
if (!_.isUndefined(options.routePrefix)) {
|
||||||
this.routePrefix = options.routePrefix;
|
this.routePrefix = options.routePrefix;
|
||||||
} else {
|
} else {
|
||||||
@ -131,7 +134,12 @@ InsightAPI.prototype.setupRoutes = function(app) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//Block routes
|
//Block routes
|
||||||
var blocks = new BlockController(this.node);
|
var blockOptions = {
|
||||||
|
node: this.node,
|
||||||
|
blockSummaryCacheSize: this.blockSummaryCacheSize,
|
||||||
|
blockCacheSize: this.blockCacheSize
|
||||||
|
};
|
||||||
|
var blocks = new BlockController(blockOptions);
|
||||||
app.get('/blocks', this.cacheShort(), blocks.list.bind(blocks));
|
app.get('/blocks', this.cacheShort(), blocks.list.bind(blocks));
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -83,7 +83,7 @@ describe('Blocks', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
it('block data should be correct', function(done) {
|
it('block data should be correct', function(done) {
|
||||||
var controller = new BlockController(node);
|
var controller = new BlockController({node: node});
|
||||||
var req = {};
|
var req = {};
|
||||||
var res = {};
|
var res = {};
|
||||||
var next = function() {
|
var next = function() {
|
||||||
@ -110,7 +110,7 @@ describe('Blocks', function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var controller = new BlockController(node);
|
var controller = new BlockController({node: node});
|
||||||
var req = {};
|
var req = {};
|
||||||
var res = {};
|
var res = {};
|
||||||
var next = function() {
|
var next = function() {
|
||||||
@ -187,7 +187,7 @@ describe('Blocks', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
it('should have correct data', function(done) {
|
it('should have correct data', function(done) {
|
||||||
var blocks = new BlockController(node);
|
var blocks = new BlockController({node: node});
|
||||||
|
|
||||||
var req = {
|
var req = {
|
||||||
query: {
|
query: {
|
||||||
@ -219,7 +219,7 @@ describe('Blocks', function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
it('should have correct data', function(done) {
|
it('should have correct data', function(done) {
|
||||||
var blocks = new BlockController(node);
|
var blocks = new BlockController({node: node});
|
||||||
|
|
||||||
var insight = {
|
var insight = {
|
||||||
'blockHash': '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7'
|
'blockHash': '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user