@onlineapps/conn-base-cache 1.0.0 → 1.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/API.md +0 -0
- package/README.md +0 -0
- package/coverage/clover.xml +0 -0
- package/coverage/coverage-final.json +0 -0
- package/coverage/lcov-report/base.css +0 -0
- package/coverage/lcov-report/block-navigation.js +0 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -0
- package/coverage/lcov-report/index.js.html +0 -0
- package/coverage/lcov-report/prettify.css +0 -0
- package/coverage/lcov-report/prettify.js +0 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -0
- package/coverage/lcov.info +0 -0
- package/onlineapps-conn-base-cache-1.0.1.tgz +0 -0
- package/package.json +3 -3
- package/src/index.js +36 -3
- package/{test → tests}/component/cache.component.test.js +1 -1
- package/{test → tests}/integration/cache.integration.test.js +1 -1
- package/{test → tests}/unit/CacheConnector.edge.test.js +1 -1
- package/{test → tests}/unit/CacheConnector.test.js +1 -1
package/API.md
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
package/coverage/clover.xml
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/coverage/lcov.info
CHANGED
|
File without changes
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onlineapps/conn-base-cache",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Redis cache connector with TTL, invalidation, and namespace support for OA Drive microservices",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "jest",
|
|
8
|
-
"test:unit": "jest
|
|
9
|
-
"test:integration": "jest
|
|
8
|
+
"test:unit": "jest tests/unit",
|
|
9
|
+
"test:integration": "jest tests/integration",
|
|
10
10
|
"test:watch": "jest --watch",
|
|
11
11
|
"docs": "jsdoc2md --files src/**/*.js > API.md"
|
|
12
12
|
},
|
package/src/index.js
CHANGED
|
@@ -68,10 +68,21 @@ class CacheConnector {
|
|
|
68
68
|
* });
|
|
69
69
|
*/
|
|
70
70
|
constructor(config = {}) {
|
|
71
|
+
// Host and port are REQUIRED - no fallbacks (fail-fast principle)
|
|
72
|
+
const host = config.host || process.env.REDIS_HOST;
|
|
73
|
+
const port = config.port || process.env.REDIS_PORT;
|
|
74
|
+
|
|
75
|
+
if (!host) {
|
|
76
|
+
throw new Error('[CacheConnector] Missing required config: host (set REDIS_HOST env or pass config.host)');
|
|
77
|
+
}
|
|
78
|
+
if (!port) {
|
|
79
|
+
throw new Error('[CacheConnector] Missing required config: port (set REDIS_PORT env or pass config.port)');
|
|
80
|
+
}
|
|
81
|
+
|
|
71
82
|
// Configuration
|
|
72
83
|
this.config = {
|
|
73
|
-
host
|
|
74
|
-
port:
|
|
84
|
+
host,
|
|
85
|
+
port: parseInt(port, 10),
|
|
75
86
|
password: config.password || process.env.REDIS_PASSWORD,
|
|
76
87
|
db: config.db || process.env.REDIS_DB || 0,
|
|
77
88
|
keyPrefix: 'cache:', // ALWAYS use cache: prefix
|
|
@@ -135,10 +146,32 @@ class CacheConnector {
|
|
|
135
146
|
* await cache.connect();
|
|
136
147
|
*/
|
|
137
148
|
async connect() {
|
|
138
|
-
|
|
149
|
+
// If already connected, return success
|
|
150
|
+
if (this.connected) {
|
|
139
151
|
return true;
|
|
140
152
|
}
|
|
141
153
|
|
|
154
|
+
// If connection is in progress, wait for it to complete
|
|
155
|
+
if (this.connecting) {
|
|
156
|
+
return new Promise((resolve, reject) => {
|
|
157
|
+
const checkInterval = setInterval(() => {
|
|
158
|
+
if (this.connected) {
|
|
159
|
+
clearInterval(checkInterval);
|
|
160
|
+
resolve(true);
|
|
161
|
+
} else if (!this.connecting) {
|
|
162
|
+
clearInterval(checkInterval);
|
|
163
|
+
reject(new Error('Connection attempt failed'));
|
|
164
|
+
}
|
|
165
|
+
}, 100);
|
|
166
|
+
|
|
167
|
+
// Timeout after 5 seconds
|
|
168
|
+
setTimeout(() => {
|
|
169
|
+
clearInterval(checkInterval);
|
|
170
|
+
reject(new Error('Connection timeout'));
|
|
171
|
+
}, 5000);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
142
175
|
this.connecting = true;
|
|
143
176
|
|
|
144
177
|
try {
|
|
@@ -11,7 +11,7 @@ const SKIP_INTEGRATION = process.env.SKIP_INTEGRATION === 'true';
|
|
|
11
11
|
const REDIS_HOST = process.env.REDIS_HOST || 'localhost';
|
|
12
12
|
const REDIS_PORT = process.env.REDIS_PORT || 6379;
|
|
13
13
|
|
|
14
|
-
describe('CacheConnector - Integration Tests', () => {
|
|
14
|
+
describe('CacheConnector - Integration Tests @integration', () => {
|
|
15
15
|
if (SKIP_INTEGRATION) {
|
|
16
16
|
it.skip('Skipping integration tests (SKIP_INTEGRATION=true)', () => {});
|
|
17
17
|
return;
|
|
@@ -9,7 +9,7 @@ jest.mock('ioredis');
|
|
|
9
9
|
const Redis = require('ioredis');
|
|
10
10
|
const CacheConnector = require('../../src/index');
|
|
11
11
|
|
|
12
|
-
describe('CacheConnector - Edge Cases & Full Coverage', () => {
|
|
12
|
+
describe('CacheConnector - Edge Cases & Full Coverage @unit', () => {
|
|
13
13
|
let cacheConnector;
|
|
14
14
|
let mockRedisClient;
|
|
15
15
|
|
|
@@ -9,7 +9,7 @@ jest.mock('ioredis');
|
|
|
9
9
|
const Redis = require('ioredis');
|
|
10
10
|
const CacheConnector = require('../../src/index');
|
|
11
11
|
|
|
12
|
-
describe('CacheConnector - Unit Tests', () => {
|
|
12
|
+
describe('CacheConnector - Unit Tests @unit', () => {
|
|
13
13
|
let cacheConnector;
|
|
14
14
|
let mockRedisClient;
|
|
15
15
|
|