From 1d7a61f688f738d6d6c07cb52c211d1e05986dda Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Fri, 20 Sep 2024 23:23:22 +0000 Subject: [PATCH] constructor: Add backwards compatibility with file-system-cache ns option --- index.mjs | 2 +- package.json | 2 +- test/fscache.test.mjs | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/index.mjs b/index.mjs index b4fdb5e..0f5d3a0 100644 --- a/index.mjs +++ b/index.mjs @@ -10,7 +10,7 @@ export default class FSCache { this.fsPromises = fsPromises || fsPromisesOriginal this.id = crypto.randomBytes(15).toString('base64').replace(/\//g, '-') - this.prefix = options.prefix ? options.prefix + '-' : '-' + this.prefix = (options.ns || options.prefix || '') + '-' this.hash_alg = options.hash_alg || 'md5' this.cache_dir = options.cache_dir || path.join(os.tmpdir(), this.id) this.ttl = options.ttl || 0 diff --git a/package.json b/package.json index d0948f1..23bac09 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fs-cache-fast", - "version": "1.0.1", + "version": "1.0.2", "description": "Cache stored on the file system", "main": "index.mjs", "scripts": { diff --git a/test/fscache.test.mjs b/test/fscache.test.mjs index 547c109..6322226 100644 --- a/test/fscache.test.mjs +++ b/test/fscache.test.mjs @@ -61,6 +61,16 @@ t.describe('#constructor()', function() { assert.strictEqual(cache.ttl, assertTtl) }) + t.test('supports alternative way of specifying prefix', function() { + const assertPrefix = 'blablabutmore' + + let cache = createCache({ + ns: assertPrefix, + }) + + assert.strictEqual(cache.prefix, assertPrefix + '-') + }) + t.test('should create the directory by default', function() { assert.notOk(fsSync.mkdirSync.called) let cache = createCache({})