UNPKG

eth-rpc-cache

Version:

A simple cache for Ethereum RPC requests extensible with different caching strategies

42 lines (41 loc) 1.42 kB
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; // These methods could be permanently cached if executed i.e. on an old block. // For newer blocks, the results could change in the case of a [deep] reorg. var mayBeSafeMethods = [ 'eth_call', 'eth_getBalance', 'eth_getBlockByNumber', 'eth_getBlockTransactionCountByNumber', 'eth_getCode', 'eth_getLogs', 'eth_getProof', 'eth_getRawTransactionByBlockNumberAndIndex', 'eth_getStorageAt', 'eth_getTransactionByBlockNumberAndIndex', 'eth_getTransactionCount', 'eth_getTransactionReceipt', 'eth_getUncleByBlockNumberAndIndex', 'eth_getUncleCountByBlockNumber' ]; // These methods can be cached at most until a new block is mined. var perBlockMethods = [ 'eth_blockNumber', 'eth_feeHistory', 'eth_getFilterChanges', 'eth_getFilterLogs', 'eth_getWork' ]; var methods = __spreadArray(__spreadArray([], mayBeSafeMethods, true), perBlockMethods, true); export var perBlockStrategy = { maxAge: 6000, // Half block time: ~6 sec. methods: methods, name: 'block' };