Skip to content

Commit

Permalink
fix(config): Memoization (#3)
Browse files Browse the repository at this point in the history
* fix memoization

memo wrapper was created per function call, so it was never memoizing

* chore: small tweak

---------

Co-authored-by: Andrew Powell <[email protected]>
  • Loading branch information
atticoos and shellscape authored Aug 30, 2024
1 parent e6546b0 commit 8e4d22d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export const init = <TDefaults, TSecrets, TSsm>({
return result;
};

const memFn = mem(getBase, { cacheKey: (args) => JSON.stringify(args) });

/* eslint-disable no-redeclare */
function get(
key: keyof typeof defaults | keyof typeof secretKeys | keyof typeof ssmKeys
Expand All @@ -80,8 +82,7 @@ export const init = <TDefaults, TSecrets, TSsm>({

if (process.env.DOT_CONFIG_DISABLE_CACHE) return getBase(key);

const fn = mem(getBase, { cacheKey: (args) => JSON.stringify(args) });
return fn(key);
return memFn(key);
}

const put = (key: keyof typeof ssmKeys, value: string) => {
Expand Down

0 comments on commit 8e4d22d

Please sign in to comment.