Add rpcCacheCapacity option to ApiOptions (#6020)
This commit is contained in:
@@ -11,7 +11,7 @@ import type { RpcCoreStats, RpcInterfaceMethod } from './types/index.js';
|
||||
|
||||
import { Observable, publishReplay, refCount } from 'rxjs';
|
||||
|
||||
import { DEFAULT_CAPACITY, LRUCache } from '@polkadot/rpc-provider';
|
||||
import { LRUCache } from '@polkadot/rpc-provider';
|
||||
import { rpcDefinitions } from '@polkadot/types';
|
||||
import { hexToU8a, isFunction, isNull, isUndefined, lazyMethod, logger, memoize, objectSpread, u8aConcat, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
@@ -33,6 +33,7 @@ type MemoizedRpcInterfaceMethod = Memoized<RpcInterfaceMethod> & {
|
||||
interface Options {
|
||||
isPedantic?: boolean;
|
||||
provider: ProviderInterface;
|
||||
rpcCacheCapacity?: number;
|
||||
userRpc?: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>;
|
||||
}
|
||||
|
||||
@@ -47,6 +48,8 @@ const EMPTY_META = {
|
||||
}
|
||||
};
|
||||
|
||||
const RPC_CORE_DEFAULT_CAPACITY = 1024 * 10 * 10;
|
||||
|
||||
// utility method to create a nicely-formatted error
|
||||
/** @internal */
|
||||
function logErrorMessage (method: string, { noErrorLog, params, type }: DefinitionRpc, error: Error): void {
|
||||
@@ -109,7 +112,7 @@ export class RpcCore {
|
||||
* Default constructor for the core RPC handler
|
||||
* @param {ProviderInterface} provider An API provider using any of the supported providers (HTTP, SC or WebSocket)
|
||||
*/
|
||||
constructor (instanceId: string, registry: Registry, { isPedantic = true, provider, userRpc = {} }: Options) {
|
||||
constructor (instanceId: string, registry: Registry, { isPedantic = true, provider, rpcCacheCapacity, userRpc = {} }: Options) {
|
||||
if (!provider || !isFunction(provider.send)) {
|
||||
throw new Error('Expected Provider to API create');
|
||||
}
|
||||
@@ -123,7 +126,7 @@ export class RpcCore {
|
||||
|
||||
// these are the base keys (i.e. part of jsonrpc)
|
||||
this.sections.push(...sectionNames);
|
||||
this.#storageCache = new LRUCache(DEFAULT_CAPACITY * 10 * 10);
|
||||
this.#storageCache = new LRUCache(rpcCacheCapacity || RPC_CORE_DEFAULT_CAPACITY);
|
||||
// decorate all interfaces, defined and user on this instance
|
||||
this.addUserInterfaces(userRpc);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user