Skip to content

Commit

Permalink
Extract cache key to const
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Jan 7, 2024
1 parent 48a01ec commit 500c3d6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ console.info('---');

// Initialize the cache.
const cache = new NodeCache({ stdTTL: stdTTL, checkperiod: checkperiod });
const CACHE_KEY = 'estimates';

/**
* Fetches data from the given URL with a timeout.
Expand Down Expand Up @@ -134,7 +135,7 @@ async function fetchData() {
* Gets the current fee estimates from the cache or fetches them if they are not cached.
*/
async function getEstimates() : Promise<Estimates> {
let estimates: Estimates | undefined = cache.get('estimates');
let estimates: Estimates | undefined = cache.get(CACHE_KEY);

if (!estimates) {
const results = await fetchData();
Expand All @@ -148,7 +149,7 @@ async function getEstimates() : Promise<Estimates> {
fee_by_block_target: feeByBlockTarget
};

cache.set('estimates', estimates);
cache.set(CACHE_KEY, estimates);
}

console.debug('Got estimates', estimates);
Expand Down

0 comments on commit 500c3d6

Please sign in to comment.