Skip to content

Commit b0ae6a9

Browse files
committed
Add caching utils
1 parent e080d33 commit b0ae6a9

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

lib/caching-utils.js

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/caching-utils.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/caching-utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Logger } from "./logging";
2+
import { tryGetFolderBytes } from "./util";
3+
4+
/**
5+
* Returns the total size of all the specified paths.
6+
* @param paths The paths for which to calculate the total size.
7+
* @param logger A logger to record some informational messages to.
8+
* @returns The total size of all specified paths.
9+
*/
10+
export async function getTotalCacheSize(
11+
paths: string[],
12+
logger: Logger,
13+
): Promise<number> {
14+
const sizes = await Promise.all(
15+
paths.map((cacheDir) => tryGetFolderBytes(cacheDir, logger)),
16+
);
17+
return sizes.map((a) => a || 0).reduce((a, b) => a + b, 0);
18+
}

0 commit comments

Comments
 (0)