pg-cache 3.1.1 → 3.3.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.
Files changed (3) hide show
  1. package/esm/lru.js +14 -5
  2. package/lru.js +14 -5
  3. package/package.json +5 -5
package/esm/lru.js CHANGED
@@ -92,6 +92,9 @@ export class PgPoolCacheManager {
92
92
  this.closed = true;
93
93
  this.clear();
94
94
  await this.waitForDisposals();
95
+ // Re-open the cache so it can accept new entries if the process
96
+ // survives the shutdown signal (e.g. during provisioning or restart).
97
+ this.closed = false;
95
98
  }
96
99
  async waitForDisposals() {
97
100
  if (this.cleanupTasks.length === 0)
@@ -125,11 +128,17 @@ export const close = async (verbose = false) => {
125
128
  if (closePromise.promise)
126
129
  return closePromise.promise;
127
130
  closePromise.promise = (async () => {
128
- if (verbose)
129
- log.info('Closing pg cache...');
130
- await pgCache.close();
131
- if (verbose)
132
- log.success('PG cache disposed.');
131
+ try {
132
+ if (verbose)
133
+ log.info('Closing pg cache...');
134
+ await pgCache.close();
135
+ if (verbose)
136
+ log.success('PG cache disposed.');
137
+ }
138
+ finally {
139
+ // Reset so close() can be called again if the process survives.
140
+ closePromise.promise = null;
141
+ }
133
142
  })();
134
143
  return closePromise.promise;
135
144
  };
package/lru.js CHANGED
@@ -95,6 +95,9 @@ class PgPoolCacheManager {
95
95
  this.closed = true;
96
96
  this.clear();
97
97
  await this.waitForDisposals();
98
+ // Re-open the cache so it can accept new entries if the process
99
+ // survives the shutdown signal (e.g. during provisioning or restart).
100
+ this.closed = false;
98
101
  }
99
102
  async waitForDisposals() {
100
103
  if (this.cleanupTasks.length === 0)
@@ -129,11 +132,17 @@ const close = async (verbose = false) => {
129
132
  if (closePromise.promise)
130
133
  return closePromise.promise;
131
134
  closePromise.promise = (async () => {
132
- if (verbose)
133
- log.info('Closing pg cache...');
134
- await exports.pgCache.close();
135
- if (verbose)
136
- log.success('PG cache disposed.');
135
+ try {
136
+ if (verbose)
137
+ log.info('Closing pg cache...');
138
+ await exports.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
+ }
137
146
  })();
138
147
  return closePromise.promise;
139
148
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-cache",
3
- "version": "3.1.1",
3
+ "version": "3.3.2",
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.1",
33
- "@pgpmjs/types": "^2.17.0",
32
+ "@pgpmjs/logger": "^2.4.2",
33
+ "@pgpmjs/types": "^2.19.2",
34
34
  "lru-cache": "^11.2.6",
35
35
  "pg": "^8.19.0",
36
- "pg-env": "^1.5.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": "d0d7d3916b70c8d960bc13e40ac85d73ea869224"
51
+ "gitHead": "4fd2c9be786ad9ae2213453276a69723435d5315"
52
52
  }