From 942ddfbde27292712213a7eb86c112601db2e71e Mon Sep 17 00:00:00 2001 From: Jasper De Moor Date: Tue, 8 May 2018 11:11:10 +0200 Subject: [PATCH] split cache into subdirs --- src/FSCache.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/FSCache.js b/src/FSCache.js index 199dc5f671d..535ef2b4e51 100644 --- a/src/FSCache.js +++ b/src/FSCache.js @@ -20,14 +20,14 @@ class FSCache { ); } - async ensureDirExists() { - await fs.mkdirp(this.dir); + async ensureDirExists(dir = this.dir) { + await fs.mkdirp(dir); this.dirExists = true; } getCacheFile(filename) { let hash = md5(this.optionsHash + filename); - return path.join(this.dir, hash + '.json'); + return path.join(this.dir, hash.substring(0, 2), hash + '.json'); } async writeDepMtimes(data) { @@ -42,9 +42,10 @@ class FSCache { async write(filename, data) { try { - await this.ensureDirExists(); + let cacheFile = this.getCacheFile(filename); + await this.ensureDirExists(path.dirname(cacheFile)); await this.writeDepMtimes(data); - await fs.writeFile(this.getCacheFile(filename), JSON.stringify(data)); + await fs.writeFile(cacheFile, JSON.stringify(data)); this.invalidated.delete(filename); } catch (err) { logger.error('Error writing to cache', err); @@ -83,7 +84,7 @@ class FSCache { let json = await fs.readFile(cacheFile); let data = JSON.parse(json); - if (!await this.checkDepMtimes(data)) { + if (!(await this.checkDepMtimes(data))) { return null; }