Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split cache into subdirs for faster fs #1322

Merged
merged 4 commits into from Jul 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/FSCache.js
Expand Up @@ -23,13 +23,24 @@ class FSCache {
}

async ensureDirExists() {
if (this.dirExists) {
return;
}

await fs.mkdirp(this.dir);

// Create sub-directories for every possible hex value
// This speeds up large caches on many file systems since there are fewer files in a single directory.
for (let i = 0; i < 256; i++) {
await fs.mkdirp(path.join(this.dir, ('00' + i.toString(16)).slice(-2)));
}

this.dirExists = true;
}

getCacheFile(filename) {
let hash = md5(this.optionsHash + filename);
return path.join(this.dir, hash + '.json');
return path.join(this.dir, hash.slice(0, 2), hash.slice(2) + '.json');
}

async getLastModified(filename) {
Expand Down