@sebspark/promise-cache 2.0.7 → 2.0.9
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/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +32 -31
- package/dist/index.mjs +32 -31
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -25,8 +25,7 @@ declare class Persistor {
|
|
|
25
25
|
private onSuccess;
|
|
26
26
|
private readonly redis?;
|
|
27
27
|
constructor({ redis, clientId, onSuccess, onError, }: PersistorConstructorType);
|
|
28
|
-
|
|
29
|
-
startConnection(): Promise<unknown>;
|
|
28
|
+
startConnection(): Promise<void>;
|
|
30
29
|
size(): Promise<number>;
|
|
31
30
|
get<T>(key: string): Promise<GetType<T> | null>;
|
|
32
31
|
getClientId(): UUID | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -25,8 +25,7 @@ declare class Persistor {
|
|
|
25
25
|
private onSuccess;
|
|
26
26
|
private readonly redis?;
|
|
27
27
|
constructor({ redis, clientId, onSuccess, onError, }: PersistorConstructorType);
|
|
28
|
-
|
|
29
|
-
startConnection(): Promise<unknown>;
|
|
28
|
+
startConnection(): Promise<void>;
|
|
30
29
|
size(): Promise<number>;
|
|
31
30
|
get<T>(key: string): Promise<GetType<T> | null>;
|
|
32
31
|
getClientId(): UUID | undefined;
|
package/dist/index.js
CHANGED
|
@@ -98,38 +98,37 @@ var Persistor = class {
|
|
|
98
98
|
CACHE_CLIENT = createLocalMemoryClient;
|
|
99
99
|
}
|
|
100
100
|
if (!this.client || !this.client.isReady) {
|
|
101
|
-
this.
|
|
101
|
+
this.startConnection();
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
async
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (retries === 5) {
|
|
114
|
-
console.error("Error reconnecting... ", cause);
|
|
115
|
-
return false;
|
|
104
|
+
async startConnection() {
|
|
105
|
+
try {
|
|
106
|
+
await new Promise((resolve, reject) => {
|
|
107
|
+
this.client = CACHE_CLIENT({
|
|
108
|
+
...this.redis,
|
|
109
|
+
socket: {
|
|
110
|
+
reconnectStrategy: (retries, cause) => {
|
|
111
|
+
console.error(cause);
|
|
112
|
+
return 1e3 * 2 ** retries;
|
|
116
113
|
}
|
|
117
|
-
return retries * 1e3;
|
|
118
114
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
115
|
+
}).on("error", (err) => {
|
|
116
|
+
this.onError(err);
|
|
117
|
+
reject(err);
|
|
118
|
+
}).on("ready", () => {
|
|
119
|
+
this.onSuccess();
|
|
120
|
+
resolve(true);
|
|
121
|
+
}).on("reconnecting", () => {
|
|
122
|
+
console.log("reconnecting...", this.clientId);
|
|
123
|
+
}).on("end", () => {
|
|
124
|
+
console.log("end...", this.clientId);
|
|
125
|
+
});
|
|
126
|
+
this.client.connect();
|
|
130
127
|
});
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
} catch (ex) {
|
|
129
|
+
this.onError(`${ex}`);
|
|
130
|
+
console.error(ex);
|
|
131
|
+
}
|
|
133
132
|
}
|
|
134
133
|
async size() {
|
|
135
134
|
if (!this.client) {
|
|
@@ -165,8 +164,9 @@ var Persistor = class {
|
|
|
165
164
|
return {};
|
|
166
165
|
}
|
|
167
166
|
async set(key, { value, timestamp, ttl }) {
|
|
168
|
-
if (!this.client) {
|
|
169
|
-
|
|
167
|
+
if (!this.client || !this.client.isReady) {
|
|
168
|
+
console.error("Client not ready");
|
|
169
|
+
return;
|
|
170
170
|
}
|
|
171
171
|
try {
|
|
172
172
|
const serializedData = JSON.stringify({ value, ttl, timestamp });
|
|
@@ -177,8 +177,9 @@ var Persistor = class {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
async delete(key) {
|
|
180
|
-
if (!this.client) {
|
|
181
|
-
|
|
180
|
+
if (!this.client || !this.client.isReady) {
|
|
181
|
+
console.error("Client not ready");
|
|
182
|
+
return;
|
|
182
183
|
}
|
|
183
184
|
try {
|
|
184
185
|
await this.client.del(key);
|
package/dist/index.mjs
CHANGED
|
@@ -69,38 +69,37 @@ var Persistor = class {
|
|
|
69
69
|
CACHE_CLIENT = createLocalMemoryClient;
|
|
70
70
|
}
|
|
71
71
|
if (!this.client || !this.client.isReady) {
|
|
72
|
-
this.
|
|
72
|
+
this.startConnection();
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
async
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (retries === 5) {
|
|
85
|
-
console.error("Error reconnecting... ", cause);
|
|
86
|
-
return false;
|
|
75
|
+
async startConnection() {
|
|
76
|
+
try {
|
|
77
|
+
await new Promise((resolve, reject) => {
|
|
78
|
+
this.client = CACHE_CLIENT({
|
|
79
|
+
...this.redis,
|
|
80
|
+
socket: {
|
|
81
|
+
reconnectStrategy: (retries, cause) => {
|
|
82
|
+
console.error(cause);
|
|
83
|
+
return 1e3 * 2 ** retries;
|
|
87
84
|
}
|
|
88
|
-
return retries * 1e3;
|
|
89
85
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
86
|
+
}).on("error", (err) => {
|
|
87
|
+
this.onError(err);
|
|
88
|
+
reject(err);
|
|
89
|
+
}).on("ready", () => {
|
|
90
|
+
this.onSuccess();
|
|
91
|
+
resolve(true);
|
|
92
|
+
}).on("reconnecting", () => {
|
|
93
|
+
console.log("reconnecting...", this.clientId);
|
|
94
|
+
}).on("end", () => {
|
|
95
|
+
console.log("end...", this.clientId);
|
|
96
|
+
});
|
|
97
|
+
this.client.connect();
|
|
101
98
|
});
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
} catch (ex) {
|
|
100
|
+
this.onError(`${ex}`);
|
|
101
|
+
console.error(ex);
|
|
102
|
+
}
|
|
104
103
|
}
|
|
105
104
|
async size() {
|
|
106
105
|
if (!this.client) {
|
|
@@ -136,8 +135,9 @@ var Persistor = class {
|
|
|
136
135
|
return {};
|
|
137
136
|
}
|
|
138
137
|
async set(key, { value, timestamp, ttl }) {
|
|
139
|
-
if (!this.client) {
|
|
140
|
-
|
|
138
|
+
if (!this.client || !this.client.isReady) {
|
|
139
|
+
console.error("Client not ready");
|
|
140
|
+
return;
|
|
141
141
|
}
|
|
142
142
|
try {
|
|
143
143
|
const serializedData = JSON.stringify({ value, ttl, timestamp });
|
|
@@ -148,8 +148,9 @@ var Persistor = class {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
async delete(key) {
|
|
151
|
-
if (!this.client) {
|
|
152
|
-
|
|
151
|
+
if (!this.client || !this.client.isReady) {
|
|
152
|
+
console.error("Client not ready");
|
|
153
|
+
return;
|
|
153
154
|
}
|
|
154
155
|
try {
|
|
155
156
|
await this.client.del(key);
|