@@ -183,8 +183,6 @@ export class BaseVersions implements Versions {
183
183
}
184
184
}
185
185
186
- const VERSION_CACHE_TTL_MS = 4 * 60 * 60 * 1000 ; // cache for N hours
187
-
188
186
/**
189
187
* Implementation of Versions that self-populates from release information at
190
188
* https://releases.electronjs.org/releases.json .
@@ -210,6 +208,11 @@ export class ElectronVersions extends BaseVersions {
210
208
return json ;
211
209
}
212
210
211
+ private static isCacheFresh ( cacheTimeMs : number , now : number ) : boolean {
212
+ const VERSION_CACHE_TTL_MS = 4 * 60 * 60 * 1000 ; // cache for N hours
213
+ return now <= cacheTimeMs + VERSION_CACHE_TTL_MS ;
214
+ }
215
+
213
216
public static async create (
214
217
paths : Partial < Paths > = { } ,
215
218
) : Promise < ElectronVersions > {
@@ -220,10 +223,10 @@ export class ElectronVersions extends BaseVersions {
220
223
const now = Date . now ( ) ;
221
224
try {
222
225
const st = await fs . stat ( versionsCache ) ;
223
- if ( now <= st . mtimeMs + VERSION_CACHE_TTL_MS )
226
+ if ( ElectronVersions . isCacheFresh ( st . mtimeMs , now ) )
224
227
versions = ( await fs . readJson ( versionsCache ) ) as unknown ;
225
228
} catch ( err ) {
226
- // cache file missing
229
+ // cache file missing or cannot be read
227
230
}
228
231
229
232
if ( ! versions ) {
@@ -244,7 +247,7 @@ export class ElectronVersions extends BaseVersions {
244
247
// if it's still fresh, do nothing
245
248
const { mtimeMs, versionsCache } = this ;
246
249
const now = Date . now ( ) ;
247
- if ( now <= mtimeMs + VERSION_CACHE_TTL_MS ) return ;
250
+ if ( ElectronVersions . isCacheFresh ( mtimeMs , now ) ) return ;
248
251
249
252
// update the cache
250
253
try {
0 commit comments