Skip to content

Commit

Permalink
fix: add modified date to files key
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Apr 30, 2021
1 parent 125ca75 commit 5a68300
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions core/instrument/src/misc/chached-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ export class CachedFileResource<T> {
? this.filePath
: [this.filePath];
return files
.reduce((acc, f) => acc.update(f), createHash('md5').update(version))
.reduce(
(acc, f) =>
acc.update(f).update(
fs
.statSync(f)
.mtime.getTime()
.toString(),
),
createHash('md5').update(version),
)
.digest('hex');
};
/**
Expand All @@ -57,19 +66,11 @@ export class CachedFileResource<T> {
get = (): T | undefined => {
const cachedFileName = this.getCachedFile();
if (fs.existsSync(cachedFileName)) {
const cacheModified = fs.statSync(cachedFileName).mtime.getTime();
const fileModified = Array.isArray(this.filePath)
? this.filePath.reduce((m, f) => {
return Math.max(m, fs.statSync(f).mtime.getTime());
}, 0)
: fs.statSync(this.filePath).mtime.getTime();
if (cacheModified >= fileModified) {
const fileData = fs.readFileSync(cachedFileName, 'utf8');
const json = JSON.parse(fileData);
if (json.hasOwnProperty('key') && json.hasOwnProperty('data')) {
if (json.key === this.getKey()) {
return json['data'];
}
const fileData = fs.readFileSync(cachedFileName, 'utf8');
const json = JSON.parse(fileData);
if (json.hasOwnProperty('key') && json.hasOwnProperty('data')) {
if (json.key === this.getKey()) {
return json['data'];
}
return undefined;
}
Expand Down

0 comments on commit 5a68300

Please sign in to comment.