Skip to content

Commit

Permalink
Split cache into subdirs for faster fs (#1322)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeMoorJasper authored and devongovett committed Jul 22, 2018
1 parent b63c2ac commit c0a84ae
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit c0a84ae

Please sign in to comment.