Skip to content

Commit

Permalink
fix: generated a custom key for the cache in blocks endpoint (#1381)
Browse files Browse the repository at this point in the history
* fix: generated a custom key for the cache in blocks endpoint

* removed 2 options from the key
  • Loading branch information
Imod7 committed Jan 12, 2024
1 parent ca163c7 commit 17cbd2c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/services/blocks/BlocksService.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -112,8 +112,12 @@ export class BlocksService extends AbstractService {
): Promise<IBlock> {
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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 17cbd2c

Please sign in to comment.