From 45fdf1d25cf8751a3cff9cd90d2a536f2da1b760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Wujas?= Date: Thu, 1 Dec 2016 17:55:03 +0100 Subject: [PATCH 1/3] fixes not using file data when using get without previously setting the value --- .gitignore | 4 +++- index.js | 10 +--------- package.json | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 709cf83..2fb9d5b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ node_modules/ tmp temp/ -*.tgz \ No newline at end of file +*.tgz +.idea +*.iml diff --git a/index.js b/index.js index c84c27a..f767cdf 100644 --- a/index.js +++ b/index.js @@ -45,21 +45,13 @@ FileStore.prototype.get = function get(key, fn) { return fn(null, null); } - if (!this.cache[key]) { - return fn(null, null); - } - if (!data) return fn(null, data); if (data.expire < Date.now()) { this.del(key); return fn(null, null); } - try { - val = JSON.parse(data.value); - } catch (e) { - return fn(e); - } + val = data.value; process.nextTick(function tick() { fn(null, val); diff --git a/package.json b/package.json index 831ec65..51896eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cacheman-file", - "version": "0.2.1", + "version": "0.2.2", "description": "File caching library for Node.JS and also cache engine for cacheman", "author": "Taron Foxworth ", "contributors": [ From 968453b05b923fa3cc0e32f0f42ae9a46d95b106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Wujas?= Date: Thu, 1 Dec 2016 18:16:57 +0100 Subject: [PATCH 2/3] fixes value isn't parsed from json --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f767cdf..6eb2a39 100644 --- a/index.js +++ b/index.js @@ -51,7 +51,11 @@ FileStore.prototype.get = function get(key, fn) { return fn(null, null); } - val = data.value; + try { + val = JSON.parse(data.value); + } catch (e) { + return fn(e); + } process.nextTick(function tick() { fn(null, val); From 35d7a0947da28e5f1b31e2864e74ba99297c6902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Wujas?= Date: Fri, 2 Dec 2016 09:30:54 +0100 Subject: [PATCH 3/3] fix removing json from filename to get cache key --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 6eb2a39..6d209c0 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ function FileStore(options) { var cacheFiles = Fs.readdirSync(self.tmpDir); self.cache = {}; cacheFiles.forEach(function(file) { - file = file.replace('.json', ''); + file = file.replace(/\.json$/, ''); self.cache[file] = true; }); } @@ -45,6 +45,10 @@ FileStore.prototype.get = function get(key, fn) { return fn(null, null); } + if (!this.cache[key]) { + return fn(null, null); + } + if (!data) return fn(null, data); if (data.expire < Date.now()) { this.del(key);