mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 07:51:55 +03:00
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
23 lines
826 B
JavaScript
23 lines
826 B
JavaScript
const defaultCacheManager = require('cache-manager-ioredis');
|
|
let redisStoreSingletonInstance;
|
|
|
|
/**
|
|
*
|
|
* @param {object} [storeOptions] options to pass to the Redis store instance
|
|
* @param {boolean} [reuseConnection] specifies if the Redis store/connection should be reused within the process
|
|
* @param {object} [CacheManager] CacheManager constructor to instantiate, defaults to cache-manager-ioredis
|
|
*/
|
|
const getRedisStore = (storeOptions, reuseConnection = true, CacheManager = defaultCacheManager) => {
|
|
if (storeOptions && reuseConnection) {
|
|
if (!redisStoreSingletonInstance) {
|
|
redisStoreSingletonInstance = CacheManager.create(storeOptions);
|
|
}
|
|
|
|
return redisStoreSingletonInstance;
|
|
} else {
|
|
return CacheManager;
|
|
}
|
|
};
|
|
|
|
module.exports.getRedisStore = getRedisStore;
|