exframe-cache-manager 1.3.3 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dockerfile +4 -4
- package/index.js +28 -38
- package/package.json +12 -12
- package/test/cacheManager.test.js +1 -2
package/Dockerfile
CHANGED
|
@@ -7,11 +7,11 @@ RUN apk update && \
|
|
|
7
7
|
addgroup -S docker && adduser -S -G docker docker
|
|
8
8
|
|
|
9
9
|
COPY ./package.json /app/package.json
|
|
10
|
-
WORKDIR /app
|
|
11
|
-
RUN npm install && \
|
|
12
|
-
npm cache clean --force
|
|
13
|
-
|
|
14
10
|
COPY . /app
|
|
15
11
|
|
|
12
|
+
WORKDIR /app
|
|
13
|
+
RUN yarn install
|
|
14
|
+
RUN npm run peers
|
|
15
|
+
|
|
16
16
|
# Override the command, to run the test instead of the application
|
|
17
17
|
CMD ["npm", "run", "unit-test"]
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const CacheManager = require('cache-manager');
|
|
4
|
-
const RedisStore = require('cache-manager-redis');
|
|
4
|
+
const RedisStore = require('cache-manager-redis-store');
|
|
5
5
|
const util = require('util');
|
|
6
6
|
const { lazyInstrument } = require('exframe-metrics');
|
|
7
7
|
|
|
@@ -27,13 +27,25 @@ function cachemanager(options) {
|
|
|
27
27
|
|
|
28
28
|
// @ts-ignore
|
|
29
29
|
const redisStore = redisCache.store;
|
|
30
|
+
const redisClient = redisStore.getClient();
|
|
31
|
+
redisClient.setMaxListeners(0);
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
redisClient.on('error', (e) => {
|
|
34
|
+
console.log('Unhandled Redis Error', { errorDetails: e }); // eslint-disable-line
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
process.on('beforeExit', () => {
|
|
38
|
+
if (redisClient.connected) {
|
|
39
|
+
redisClient.removeAllListeners();
|
|
40
|
+
redisClient.end(true);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
35
43
|
|
|
36
44
|
const instance = {
|
|
45
|
+
get cacheStorePool() {
|
|
46
|
+
return redisClient;
|
|
47
|
+
},
|
|
48
|
+
|
|
37
49
|
/**
|
|
38
50
|
*
|
|
39
51
|
* @param {string} key
|
|
@@ -100,33 +112,20 @@ function cachemanager(options) {
|
|
|
100
112
|
|
|
101
113
|
close() {
|
|
102
114
|
return new Promise(res => {
|
|
103
|
-
|
|
115
|
+
redisClient.removeAllListeners();
|
|
116
|
+
redisClient.end(true);
|
|
117
|
+
res();
|
|
104
118
|
});
|
|
105
119
|
},
|
|
106
120
|
|
|
107
121
|
getClient() {
|
|
108
122
|
return new Promise((resolve, reject) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (connError) {
|
|
113
|
-
return reject(connError);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (client.connected) {
|
|
117
|
-
return resolve(client);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
client.once('ready', () => {
|
|
121
|
-
clearTimeout(timeout);
|
|
122
|
-
resolve(client);
|
|
123
|
-
});
|
|
123
|
+
if (redisClient.connected) {
|
|
124
|
+
return resolve(redisClient);
|
|
125
|
+
}
|
|
124
126
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
reject(new Error('Timeout waiting for redis client connection'));
|
|
128
|
-
}, 10000);
|
|
129
|
-
}, db);
|
|
127
|
+
redisClient.on('ready', () => resolve(redisClient));
|
|
128
|
+
redisClient.on('error', (e) => reject(e));
|
|
130
129
|
});
|
|
131
130
|
},
|
|
132
131
|
|
|
@@ -135,17 +134,8 @@ function cachemanager(options) {
|
|
|
135
134
|
* @param {(client: any) => any} fn
|
|
136
135
|
*/
|
|
137
136
|
async processRedisCommands(fn) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
try {
|
|
142
|
-
client = await this.getClient();
|
|
143
|
-
result = await fn(client);
|
|
144
|
-
} finally {
|
|
145
|
-
if (client) {
|
|
146
|
-
cacheStorePool.release(client);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
137
|
+
const client = await this.getClient();
|
|
138
|
+
const result = await fn(client);
|
|
149
139
|
|
|
150
140
|
return result;
|
|
151
141
|
},
|
|
@@ -173,7 +163,7 @@ function cachemanager(options) {
|
|
|
173
163
|
} while (cursor !== '0');
|
|
174
164
|
});
|
|
175
165
|
},
|
|
176
|
-
|
|
166
|
+
redisClient
|
|
177
167
|
};
|
|
178
168
|
|
|
179
169
|
Object.keys(instance).forEach((key) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "exframe-cache-manager",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Managing the cache",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"config": {
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"pretest": "npm-install-peers && npm run lint",
|
|
14
14
|
"lint": "eslint ./",
|
|
15
|
+
"peers": "npm-install-peers",
|
|
15
16
|
"test": "docker-compose -f docker-compose.yml up --abort-on-container-exit --exit-code-from exframe-cache-manager",
|
|
16
|
-
"unit-test": "./node_modules/.bin/nyc -r lcov --report-dir ./documentation/coverage -t ./documentation/coverage mocha --reporter $npm_package_config_reporter \"./test/**/*.test.js\""
|
|
17
|
+
"unit-test": "./node_modules/.bin/nyc -r lcov --report-dir ./documentation/coverage -t ./documentation/coverage mocha --exit --reporter $npm_package_config_reporter \"./test/**/*.test.js\""
|
|
17
18
|
},
|
|
18
19
|
"author": "Exzeo",
|
|
19
20
|
"license": "ISC",
|
|
@@ -24,26 +25,25 @@
|
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"@types/cache-manager": "^3.4.2",
|
|
27
|
-
"@types/redis": "^2.8.32",
|
|
28
28
|
"cache-manager": "^3.6.0",
|
|
29
|
-
"cache-manager-redis": "^0.
|
|
30
|
-
"exframe-metrics": "^1.1.0"
|
|
31
|
-
"redis": "^3.1.2"
|
|
29
|
+
"cache-manager-redis-store": "^2.0.0",
|
|
30
|
+
"exframe-metrics": "^1.1.0"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
|
-
"chai": "
|
|
35
|
-
"eslint": "
|
|
33
|
+
"chai": "*",
|
|
34
|
+
"eslint": "*",
|
|
36
35
|
"eslint-config-exzeo": "*",
|
|
37
|
-
"eslint-plugin-import": "
|
|
36
|
+
"eslint-plugin-import": "*",
|
|
38
37
|
"mocha": "*",
|
|
39
|
-
"mocha-exzeo-reporter": "
|
|
38
|
+
"mocha-exzeo-reporter": "*",
|
|
40
39
|
"npm-install-peers": "*",
|
|
41
|
-
"nyc": "*"
|
|
40
|
+
"nyc": "*",
|
|
41
|
+
"sinon": "*"
|
|
42
42
|
},
|
|
43
43
|
"repository": {
|
|
44
44
|
"type": "git",
|
|
45
45
|
"url": "https://bitbucket.org/exzeo-usa/exframe",
|
|
46
46
|
"directory": "packages/exframe-cache-manager"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "3ff1cd2d1bc50184f5aae8d1ea35e04e1cb718b2"
|
|
49
49
|
}
|
|
@@ -105,7 +105,7 @@ context('Test User Profile Middleware', () => {
|
|
|
105
105
|
const result = await app1.getItem(cacheKey);
|
|
106
106
|
expect(result).to.not.be.ok();
|
|
107
107
|
} catch (ex) {
|
|
108
|
-
expect(ex.message).to.be.equal('
|
|
108
|
+
expect(ex.message).to.be.equal('GET can\'t be processed. The connection is already closed.');
|
|
109
109
|
const metrics = prometheusClient.register.getMetricsAsArray().filter((m) => m.name.includes('close'));
|
|
110
110
|
expect(metrics).to.be.an('array').and.to.have.lengthOf.above(0);
|
|
111
111
|
}
|
|
@@ -122,7 +122,6 @@ context('Test User Profile Middleware', () => {
|
|
|
122
122
|
it('validate the cacheStorePool', () => {
|
|
123
123
|
const catchepool = app.cacheStorePool;
|
|
124
124
|
expect(app).to.not.eql(null);
|
|
125
|
-
expect(catchepool.db).to.eql(0);
|
|
126
125
|
expect(catchepool._maxListeners).to.eql(0);
|
|
127
126
|
});
|
|
128
127
|
|