-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: implement the simplest version of compilation job cache
- Loading branch information
Showing
3 changed files
with
69 additions
and
4 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
32 changes: 32 additions & 0 deletions
32
v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/cache.ts
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,32 @@ | ||
import path from "node:path"; | ||
|
||
import { | ||
exists, | ||
readJsonFile, | ||
writeJsonFile, | ||
} from "@ignored/hardhat-vnext-utils/fs"; | ||
|
||
export class Cache { | ||
readonly #basePath: string; | ||
readonly #namespace: string; | ||
|
||
constructor(basePath: string, namespace: string) { | ||
this.#basePath = basePath; | ||
this.#namespace = namespace; | ||
|
||
console.log(`Using cache at ${this.#basePath}`); | ||
} | ||
|
||
public async getJson<T>(key: string): Promise<T | undefined> { | ||
const filePath = path.join(this.#basePath, this.#namespace, key); | ||
if (await exists(filePath)) { | ||
return readJsonFile<T>(filePath); | ||
} | ||
return undefined; | ||
} | ||
|
||
public async setJson<T>(key: string, value: T): Promise<void> { | ||
const filePath = path.join(this.#basePath, this.#namespace, key); | ||
await writeJsonFile(filePath, value); | ||
} | ||
} |
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