From 58665d3e56437e612731fd86b18e7fe348280a94 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 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/FSCache.js b/src/FSCache.js index 8043b43e66f..db5a2f9575a 100644 --- a/src/FSCache.js +++ b/src/FSCache.js @@ -22,14 +22,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 getLastModified(filename) { @@ -56,9 +56,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.message}`);