From 17cbd2cd6af98a826ee5f64d2868e014a3249bdb Mon Sep 17 00:00:00 2001 From: Dominique Date: Fri, 12 Jan 2024 06:23:54 +0100 Subject: [PATCH] fix: generated a custom key for the cache in blocks endpoint (#1381) * fix: generated a custom key for the cache in blocks endpoint * removed 2 options from the key --- src/services/blocks/BlocksService.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/services/blocks/BlocksService.ts b/src/services/blocks/BlocksService.ts index 25703acfa..628007b6c 100644 --- a/src/services/blocks/BlocksService.ts +++ b/src/services/blocks/BlocksService.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2022 Parity Technologies (UK) Ltd. +// Copyright 2017-2024 Parity Technologies (UK) Ltd. // This file is part of Substrate API Sidecar. // // Substrate API Sidecar is free software: you can redistribute it and/or modify @@ -112,8 +112,12 @@ export class BlocksService extends AbstractService { ): Promise { const { api } = this; + // Create a key for the cache that is a concatenation of the block hash and all the query params included in the request + const cacheKey = + hash.toString() + Number(eventDocs) + Number(extrinsicDocs) + Number(checkFinalized) + Number(noFees); + // Before making any api calls check the cache if the queried block exists - const isBlockCached = this.blockStore.get(hash.toString()); + const isBlockCached = this.blockStore.get(cacheKey); if (isBlockCached && isBlockCached.finalized !== false) { return isBlockCached; @@ -203,7 +207,7 @@ export class BlocksService extends AbstractService { }; // Store the block in the cache - this.blockStore.set(hash.toString(), response); + this.blockStore.set(cacheKey, response); return response; }