Cache all module data

Summary:
We used to only cache the `dependencies` and `name` of a Module but we were actually accessing two more fields (async dependencies and the `isHaste` field) which meant we were always reading every single file from disk. In D2644383 I noticed that but realized that the Promise was cached, meaning we would read every file once *per instance* and I didn't think about cross-instance reads over time. My initial version added more caching (but also missed the `isHaste` field) but then I got rid of the cache call for `dependencies`. So my change from before didn't make anything worse but it also didn't make anything better. This change now caches everything until the contents of the file actually changes.

public

Reviewed By: martinbigio

Differential Revision: D2831569

fb-gh-sync-id: 74081abc0ce3ca96b4e56c3c9b6d24aa84f7496c
This commit is contained in:
Christoph Pojer 2016-01-14 13:47:31 -08:00 committed by facebook-github-bot-7
parent 25c3dd140f
commit 4074b7980e
1 changed files with 15 additions and 3 deletions

View File

@ -31,7 +31,11 @@ class Module {
}
isHaste() {
return this.read().then(data => !!data.id);
return this._cache.get(
this.path,
'isHaste',
() => this.read().then(data => !!data.id)
);
}
getName() {
@ -67,11 +71,19 @@ class Module {
}
getDependencies() {
return this.read().then(data => data.dependencies);
return this._cache.get(
this.path,
'dependencies',
() => this.read().then(data => data.dependencies)
);
}
getAsyncDependencies() {
return this.read().then(data => data.asyncDependencies);
return this._cache.get(
this.path,
'asyncDependencies',
() => this.read().then(data => data.asyncDependencies)
);
}
invalidate() {