Skip to content

Commit 63a644a

Browse files
authored
clean(cache): remove unused checkNewCache parameter (ezolenko#368)
- it is set to `true` in every usage, so just always check the new cache and remove the parameter entirely - rewrite the comments to reflect this change - and condense them a bit - modify tests a bit to reflect this change as well
1 parent 6977f30 commit 63a644a

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

__tests__/rollingcache.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ afterAll(() => remove(testDir));
2727

2828

2929
test("RollingCache", async () => {
30-
const cache = new RollingCache(testDir, true);
30+
const cache = new RollingCache(testDir);
3131

3232
expect(cache.exists(nonExistentFile)).toBeFalsy();
3333
expect(cache.exists(testFile)).toBeTruthy();
@@ -50,7 +50,7 @@ test("RollingCache", async () => {
5050
});
5151

5252
test("RollingCache, rolled", async () => {
53-
const cache = new RollingCache(testDir, true);
53+
const cache = new RollingCache(testDir);
5454
// roll the cache
5555
cache.roll();
5656
// rolling again hits coverage for this.rolled being true already
@@ -65,16 +65,16 @@ test("RollingCache, rolled", async () => {
6565
expect(await pathExists(`${oldCacheDir}/touched.json`)).toBeFalsy();
6666
});
6767

68-
test("RollingCache, test checkNewCache", async () => {
69-
const cache = new RollingCache(testDir, true);
68+
test("RollingCache, test newCache", async () => {
69+
const cache = new RollingCache(testDir);
7070

7171
const preExistingFile = `${newCacheDir}/pre-existing.json`;
7272
await writeFile(preExistingFile, JSON.stringify({}));
7373
expect(cache.exists("pre-existing.json")).toBeTruthy();
7474
});
7575

7676
test("RollingCache, test match when oldCacheDir is empty", () => {
77-
const cache = new RollingCache(emptyCacheRoot, true);
77+
const cache = new RollingCache(emptyCacheRoot);
7878

7979
expect(cache.match([])).toBeTruthy();
8080
expect(cache.match([testFile])).toBeFalsy();

src/rollingcache.ts

+9-19
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,21 @@ export class RollingCache<DataType> implements ICache<DataType>
1414
private newCacheRoot: string;
1515
private rolled: boolean = false;
1616

17-
/**
18-
* @param cacheRoot: root folder for the cache
19-
* @param checkNewCache: whether to also look in new cache when reading from cache
20-
*/
21-
constructor(private cacheRoot: string, private checkNewCache: boolean)
17+
/** @param cacheRoot: root folder for the cache */
18+
constructor(private cacheRoot: string)
2219
{
2320
this.oldCacheRoot = `${this.cacheRoot}/cache`;
2421
this.newCacheRoot = `${this.cacheRoot}/cache_`;
2522
emptyDirSync(this.newCacheRoot);
2623
}
2724

28-
/**
29-
* @returns true if name exist in old cache (or either old of new cache if checkNewCache is true)
30-
*/
25+
/** @returns true if name exists in either old cache or new cache */
3126
public exists(name: string): boolean
3227
{
3328
if (this.rolled)
3429
return false;
3530

36-
if (this.checkNewCache && existsSync(`${this.newCacheRoot}/${name}`))
31+
if (existsSync(`${this.newCacheRoot}/${name}`))
3732
return true;
3833

3934
return existsSync(`${this.oldCacheRoot}/${name}`);
@@ -44,9 +39,7 @@ export class RollingCache<DataType> implements ICache<DataType>
4439
return `${this.oldCacheRoot}/${name}`;
4540
}
4641

47-
/**
48-
* @returns true if old cache contains all names and nothing more
49-
*/
42+
/** @returns true if old cache contains all names and nothing more */
5043
public match(names: string[]): boolean
5144
{
5245
if (this.rolled)
@@ -58,12 +51,10 @@ export class RollingCache<DataType> implements ICache<DataType>
5851
return _.isEqual(readdirSync(this.oldCacheRoot).sort(), names.sort());
5952
}
6053

61-
/**
62-
* @returns data for name, must exist in old cache (or either old of new cache if checkNewCache is true)
63-
*/
54+
/** @returns data for name, must exist in either old cache or new cache */
6455
public read(name: string): DataType | null | undefined
6556
{
66-
if (this.checkNewCache && existsSync(`${this.newCacheRoot}/${name}`))
57+
if (existsSync(`${this.newCacheRoot}/${name}`))
6758
return readJsonSync(`${this.newCacheRoot}/${name}`, { encoding: "utf8", throws: false });
6859

6960
return readJsonSync(`${this.oldCacheRoot}/${name}`, { encoding: "utf8", throws: false });
@@ -84,12 +75,11 @@ export class RollingCache<DataType> implements ICache<DataType>
8475
{
8576
if (this.rolled)
8677
return;
78+
8779
ensureFileSync(`${this.newCacheRoot}/${name}`);
8880
}
8981

90-
/**
91-
* clears old cache and moves new in its place
92-
*/
82+
/** clears old cache and moves new in its place */
9383
public roll()
9484
{
9585
if (this.rolled)

src/tscache.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@ export class TsCache
281281

282282
private init()
283283
{
284-
this.codeCache = new RollingCache<ICode>(`${this.cacheDir}/code`, true);
285-
this.typesCache = new RollingCache<string>(`${this.cacheDir}/types`, true);
286-
this.syntacticDiagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/syntacticDiagnostics`, true);
287-
this.semanticDiagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/semanticDiagnostics`, true);
284+
this.codeCache = new RollingCache<ICode>(`${this.cacheDir}/code`);
285+
this.typesCache = new RollingCache<string>(`${this.cacheDir}/types`);
286+
this.syntacticDiagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/syntacticDiagnostics`);
287+
this.semanticDiagnosticsCache = new RollingCache<IDiagnostics[]>(`${this.cacheDir}/semanticDiagnostics`);
288288
}
289289

290290
private markAsDirty(id: string): void

0 commit comments

Comments
 (0)