pg-cache 3.1.1 → 3.3.3
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/esm/lru.js +18 -5
- package/lru.js +18 -5
- package/package.json +7 -7
package/esm/lru.js
CHANGED
|
@@ -60,6 +60,10 @@ export class PgPoolCacheManager {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
get(key) {
|
|
63
|
+
if (this.closed) {
|
|
64
|
+
log.warn(`Cache is closed, ignoring get(${key})`);
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
63
67
|
return this.pgCache.get(key)?.pool;
|
|
64
68
|
}
|
|
65
69
|
has(key) {
|
|
@@ -92,6 +96,9 @@ export class PgPoolCacheManager {
|
|
|
92
96
|
this.closed = true;
|
|
93
97
|
this.clear();
|
|
94
98
|
await this.waitForDisposals();
|
|
99
|
+
// Re-open the cache so it can accept new entries if the process
|
|
100
|
+
// survives the shutdown signal (e.g. during provisioning or restart).
|
|
101
|
+
this.closed = false;
|
|
95
102
|
}
|
|
96
103
|
async waitForDisposals() {
|
|
97
104
|
if (this.cleanupTasks.length === 0)
|
|
@@ -125,11 +132,17 @@ export const close = async (verbose = false) => {
|
|
|
125
132
|
if (closePromise.promise)
|
|
126
133
|
return closePromise.promise;
|
|
127
134
|
closePromise.promise = (async () => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
135
|
+
try {
|
|
136
|
+
if (verbose)
|
|
137
|
+
log.info('Closing pg cache...');
|
|
138
|
+
await pgCache.close();
|
|
139
|
+
if (verbose)
|
|
140
|
+
log.success('PG cache disposed.');
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
// Reset so close() can be called again if the process survives.
|
|
144
|
+
closePromise.promise = null;
|
|
145
|
+
}
|
|
133
146
|
})();
|
|
134
147
|
return closePromise.promise;
|
|
135
148
|
};
|
package/lru.js
CHANGED
|
@@ -63,6 +63,10 @@ class PgPoolCacheManager {
|
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
get(key) {
|
|
66
|
+
if (this.closed) {
|
|
67
|
+
log.warn(`Cache is closed, ignoring get(${key})`);
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
66
70
|
return this.pgCache.get(key)?.pool;
|
|
67
71
|
}
|
|
68
72
|
has(key) {
|
|
@@ -95,6 +99,9 @@ class PgPoolCacheManager {
|
|
|
95
99
|
this.closed = true;
|
|
96
100
|
this.clear();
|
|
97
101
|
await this.waitForDisposals();
|
|
102
|
+
// Re-open the cache so it can accept new entries if the process
|
|
103
|
+
// survives the shutdown signal (e.g. during provisioning or restart).
|
|
104
|
+
this.closed = false;
|
|
98
105
|
}
|
|
99
106
|
async waitForDisposals() {
|
|
100
107
|
if (this.cleanupTasks.length === 0)
|
|
@@ -129,11 +136,17 @@ const close = async (verbose = false) => {
|
|
|
129
136
|
if (closePromise.promise)
|
|
130
137
|
return closePromise.promise;
|
|
131
138
|
closePromise.promise = (async () => {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
139
|
+
try {
|
|
140
|
+
if (verbose)
|
|
141
|
+
log.info('Closing pg cache...');
|
|
142
|
+
await exports.pgCache.close();
|
|
143
|
+
if (verbose)
|
|
144
|
+
log.success('PG cache disposed.');
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
// Reset so close() can be called again if the process survives.
|
|
148
|
+
closePromise.promise = null;
|
|
149
|
+
}
|
|
137
150
|
})();
|
|
138
151
|
return closePromise.promise;
|
|
139
152
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg-cache",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.3",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "PostgreSQL connection pool LRU cache manager",
|
|
6
6
|
"main": "index.js",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"test:watch": "jest --watch"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@pgpmjs/logger": "^2.2
|
|
33
|
-
"@pgpmjs/types": "^2.
|
|
34
|
-
"lru-cache": "^11.2.
|
|
35
|
-
"pg": "^8.
|
|
36
|
-
"pg-env": "^1.
|
|
32
|
+
"@pgpmjs/logger": "^2.4.2",
|
|
33
|
+
"@pgpmjs/types": "^2.19.2",
|
|
34
|
+
"lru-cache": "^11.2.7",
|
|
35
|
+
"pg": "^8.20.0",
|
|
36
|
+
"pg-env": "^1.7.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/pg": "^8.18.0",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"connection",
|
|
49
49
|
"constructive"
|
|
50
50
|
],
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "21fd7c2c30663548cf15aa448c1935ab56e5497d"
|
|
52
52
|
}
|