@@ -14,26 +14,21 @@ export class RollingCache<DataType> implements ICache<DataType>
14
14
private newCacheRoot : string ;
15
15
private rolled : boolean = false ;
16
16
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 )
22
19
{
23
20
this . oldCacheRoot = `${ this . cacheRoot } /cache` ;
24
21
this . newCacheRoot = `${ this . cacheRoot } /cache_` ;
25
22
emptyDirSync ( this . newCacheRoot ) ;
26
23
}
27
24
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 */
31
26
public exists ( name : string ) : boolean
32
27
{
33
28
if ( this . rolled )
34
29
return false ;
35
30
36
- if ( this . checkNewCache && existsSync ( `${ this . newCacheRoot } /${ name } ` ) )
31
+ if ( existsSync ( `${ this . newCacheRoot } /${ name } ` ) )
37
32
return true ;
38
33
39
34
return existsSync ( `${ this . oldCacheRoot } /${ name } ` ) ;
@@ -44,9 +39,7 @@ export class RollingCache<DataType> implements ICache<DataType>
44
39
return `${ this . oldCacheRoot } /${ name } ` ;
45
40
}
46
41
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 */
50
43
public match ( names : string [ ] ) : boolean
51
44
{
52
45
if ( this . rolled )
@@ -58,12 +51,10 @@ export class RollingCache<DataType> implements ICache<DataType>
58
51
return _ . isEqual ( readdirSync ( this . oldCacheRoot ) . sort ( ) , names . sort ( ) ) ;
59
52
}
60
53
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 */
64
55
public read ( name : string ) : DataType | null | undefined
65
56
{
66
- if ( this . checkNewCache && existsSync ( `${ this . newCacheRoot } /${ name } ` ) )
57
+ if ( existsSync ( `${ this . newCacheRoot } /${ name } ` ) )
67
58
return readJsonSync ( `${ this . newCacheRoot } /${ name } ` , { encoding : "utf8" , throws : false } ) ;
68
59
69
60
return readJsonSync ( `${ this . oldCacheRoot } /${ name } ` , { encoding : "utf8" , throws : false } ) ;
@@ -84,12 +75,11 @@ export class RollingCache<DataType> implements ICache<DataType>
84
75
{
85
76
if ( this . rolled )
86
77
return ;
78
+
87
79
ensureFileSync ( `${ this . newCacheRoot } /${ name } ` ) ;
88
80
}
89
81
90
- /**
91
- * clears old cache and moves new in its place
92
- */
82
+ /** clears old cache and moves new in its place */
93
83
public roll ( )
94
84
{
95
85
if ( this . rolled )
0 commit comments