cc48ead945
closes https://github.com/TryGhost/Arch/issues/85 - Added a cache configuration option to signal "reuse of redis connection" for Redis cache adapter. The connection reuse it turned on by default to be shared between caches. They rely on unique "keyPrefix" structure, so there is no collision side-effects when reusing same Redis Store. - The Redis connection options like "ttl" are shared with the first connection that's crated. So if there's a need to have unique configuration, a separate connection has to be created by passing `"reuseConnection": false` parameter
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
const assert = require('assert/strict');
|
|
const redisStoreFactory = require('../lib/redis-store-factory');
|
|
|
|
class CacheManagerMock {
|
|
static create() {
|
|
return 'StoreInstance' + new Date().getTime();
|
|
}
|
|
}
|
|
|
|
describe('Redis Store Factory', function () {
|
|
it('returns a cache manager constructor when no extra parameters are provided', function () {
|
|
const store = redisStoreFactory.getRedisStore();
|
|
|
|
assert.ok(store);
|
|
assert.ok(store.create);
|
|
});
|
|
|
|
it('reuses redis store instance', function () {
|
|
const store = redisStoreFactory.getRedisStore({}, true, CacheManagerMock);
|
|
const storeReused = redisStoreFactory.getRedisStore({}, true, CacheManagerMock);
|
|
|
|
assert.equal(store.create, undefined);
|
|
|
|
assert.equal(store.startsWith('StoreInstance'), true, 'Should be a value of the create method without a random postfix');
|
|
assert.equal(store, storeReused, 'Should be the same store instance');
|
|
|
|
const uniqueStore = redisStoreFactory.getRedisStore({}, false, CacheManagerMock);
|
|
assert.notEqual(uniqueStore, store, 'Should be a different store instances');
|
|
});
|
|
});
|