Skip to content

Commit cd0adef

Browse files
committed
chore: move cache value type declaration to the constructor
1 parent ed3328a commit cd0adef

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/build-system.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import {
4646
getContractArtifact,
4747
getDuplicatedContractNamesDeclarationFile,
4848
} from "./artifacts.js";
49-
import { Cache } from "./cache.js";
49+
import { ObjectCache } from "./cache.js";
5050
import { CompilationJobImplementation } from "./compilation-job.js";
5151
import { downloadConfiguredCompilers, getCompiler } from "./compiler/index.js";
5252
import { buildDependencyGraph } from "./dependency-graph-building.js";
@@ -76,13 +76,13 @@ export interface SolidityBuildSystemOptions {
7676

7777
export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
7878
readonly #options: SolidityBuildSystemOptions;
79-
readonly #compilerOutputCache: Cache;
79+
readonly #compilerOutputCache: ObjectCache<CompilerOutput>;
8080
readonly #defaultConcurrency = Math.max(os.cpus().length - 1, 1);
8181
#downloadedCompilers = false;
8282

8383
constructor(options: SolidityBuildSystemOptions) {
8484
this.#options = options;
85-
this.#compilerOutputCache = new Cache(
85+
this.#compilerOutputCache = new ObjectCache<CompilerOutput>(
8686
options.cachePath,
8787
"hardhat.core.solidity.build-system.compiler-output",
8888
"v1",
@@ -141,7 +141,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
141141

142142
if (runCompilationJobOptions?.force !== true) {
143143
const cachedCompilerOutput =
144-
await this.#compilerOutputCache.getJson<CompilerOutput>(buildId);
144+
await this.#compilerOutputCache.get(buildId);
145145
if (cachedCompilerOutput !== undefined) {
146146
log(`Using cached compiler output for build ${buildId}`);
147147
return {
@@ -180,7 +180,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
180180
// will only care about the result of these operations in subsequent runs
181181
void Promise.all(
182182
uncachedSuccessfulResults.map(async (result) => {
183-
return this.#compilerOutputCache.setJson(
183+
return this.#compilerOutputCache.set(
184184
result.compilationJob.getBuildId(),
185185
result.compilerOutput,
186186
);

v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/cache.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
writeJsonFile,
1111
} from "@ignored/hardhat-vnext-utils/fs";
1212

13-
export class Cache {
13+
export class ObjectCache<T> {
1414
readonly #path: string;
1515
readonly #maxAgeMs: number = 0;
1616
readonly #maxSize: number = 0;
@@ -19,12 +19,12 @@ export class Cache {
1919
this.#path = path.join(basePath, namespace, version);
2020
}
2121

22-
public async setJson<T>(key: string, value: T): Promise<void> {
22+
public async set(key: string, value: T): Promise<void> {
2323
const filePath = path.join(this.#path, key);
2424
await writeJsonFile(filePath, value);
2525
}
2626

27-
public async getJson<T>(key: string): Promise<T | undefined> {
27+
public async get(key: string): Promise<T | undefined> {
2828
const filePath = path.join(this.#path, key);
2929
return (await exists(filePath)) ? readJsonFile<T>(filePath) : undefined;
3030
}

0 commit comments

Comments
 (0)