-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build-cache): add build-cache to support incremental builds
- Loading branch information
1 parent
0e9fa97
commit 63e64f4
Showing
3 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const createBuildCache = ( | ||
buildCallback: (key: string, input: string) => Promise<string> | string | ||
) => { | ||
const cache = new Map<string, { input: string; output: string }>(); | ||
return async (key: string, input: string) => { | ||
let cacheEntry = cache.get(key); | ||
if (cacheEntry == null || cacheEntry?.input !== input) { | ||
cacheEntry = { input, output: await buildCallback(key, input) }; | ||
cache.set(key, cacheEntry); | ||
return cacheEntry.output; | ||
} | ||
return cacheEntry.output; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters