@sebspark/promise-cache 1.2.0 → 1.2.1
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 +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +17 -5
- package/dist/index.mjs +16 -5
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -23,6 +23,7 @@ declare class Persistor {
|
|
|
23
23
|
delete(key: string): Promise<void>;
|
|
24
24
|
}
|
|
25
25
|
declare const createPersistor: (redis?: RedisClientOptions) => Persistor;
|
|
26
|
+
declare const clean: () => void;
|
|
26
27
|
|
|
27
28
|
declare class PromiseCache<U> {
|
|
28
29
|
persistor: Persistor;
|
|
@@ -69,7 +70,7 @@ declare class LocalStorage {
|
|
|
69
70
|
client: Map<any, any>;
|
|
70
71
|
get(key: string): any;
|
|
71
72
|
set(key: string, value: string, options?: {
|
|
72
|
-
|
|
73
|
+
PX: number;
|
|
73
74
|
}): void;
|
|
74
75
|
del(key: string): void;
|
|
75
76
|
clear(): void;
|
|
@@ -79,4 +80,4 @@ declare class LocalStorage {
|
|
|
79
80
|
}
|
|
80
81
|
declare const createLocalMemoryClient: () => LocalStorage;
|
|
81
82
|
|
|
82
|
-
export { LocalStorage, Persistor, PromiseCache, createLocalMemoryClient, createPersistor };
|
|
83
|
+
export { LocalStorage, Persistor, PromiseCache, clean, createLocalMemoryClient, createPersistor };
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ declare class Persistor {
|
|
|
23
23
|
delete(key: string): Promise<void>;
|
|
24
24
|
}
|
|
25
25
|
declare const createPersistor: (redis?: RedisClientOptions) => Persistor;
|
|
26
|
+
declare const clean: () => void;
|
|
26
27
|
|
|
27
28
|
declare class PromiseCache<U> {
|
|
28
29
|
persistor: Persistor;
|
|
@@ -69,7 +70,7 @@ declare class LocalStorage {
|
|
|
69
70
|
client: Map<any, any>;
|
|
70
71
|
get(key: string): any;
|
|
71
72
|
set(key: string, value: string, options?: {
|
|
72
|
-
|
|
73
|
+
PX: number;
|
|
73
74
|
}): void;
|
|
74
75
|
del(key: string): void;
|
|
75
76
|
clear(): void;
|
|
@@ -79,4 +80,4 @@ declare class LocalStorage {
|
|
|
79
80
|
}
|
|
80
81
|
declare const createLocalMemoryClient: () => LocalStorage;
|
|
81
82
|
|
|
82
|
-
export { LocalStorage, Persistor, PromiseCache, createLocalMemoryClient, createPersistor };
|
|
83
|
+
export { LocalStorage, Persistor, PromiseCache, clean, createLocalMemoryClient, createPersistor };
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(src_exports, {
|
|
|
23
23
|
LocalStorage: () => LocalStorage,
|
|
24
24
|
Persistor: () => Persistor,
|
|
25
25
|
PromiseCache: () => PromiseCache,
|
|
26
|
+
clean: () => clean,
|
|
26
27
|
createLocalMemoryClient: () => createLocalMemoryClient,
|
|
27
28
|
createPersistor: () => createPersistor
|
|
28
29
|
});
|
|
@@ -39,10 +40,10 @@ var LocalStorage = class {
|
|
|
39
40
|
}
|
|
40
41
|
set(key, value, options) {
|
|
41
42
|
this.client.set(key, value);
|
|
42
|
-
if (options == null ? void 0 : options.
|
|
43
|
+
if (options == null ? void 0 : options.PX) {
|
|
43
44
|
setTimeout(() => {
|
|
44
45
|
this.client.delete(key);
|
|
45
|
-
}, options.
|
|
46
|
+
}, options.PX);
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
del(key) {
|
|
@@ -139,7 +140,7 @@ var Persistor = class {
|
|
|
139
140
|
}
|
|
140
141
|
createOptions(ttl) {
|
|
141
142
|
if (ttl !== null && ttl !== void 0) {
|
|
142
|
-
return {
|
|
143
|
+
return { PX: Math.round(ttl) };
|
|
143
144
|
}
|
|
144
145
|
return {};
|
|
145
146
|
}
|
|
@@ -166,9 +167,19 @@ var Persistor = class {
|
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
169
|
};
|
|
170
|
+
var _persistors = {};
|
|
169
171
|
var createPersistor = (redis) => {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
+
if (redis) {
|
|
173
|
+
const key = JSON.stringify(redis);
|
|
174
|
+
if (!_persistors[key]) {
|
|
175
|
+
const persistor = new Persistor(redis);
|
|
176
|
+
}
|
|
177
|
+
return _persistors[key];
|
|
178
|
+
}
|
|
179
|
+
return new Persistor();
|
|
180
|
+
};
|
|
181
|
+
var clean = () => {
|
|
182
|
+
_persistors = {};
|
|
172
183
|
};
|
|
173
184
|
|
|
174
185
|
// src/promiseCache.ts
|
|
@@ -257,6 +268,7 @@ var PromiseCache = class {
|
|
|
257
268
|
LocalStorage,
|
|
258
269
|
Persistor,
|
|
259
270
|
PromiseCache,
|
|
271
|
+
clean,
|
|
260
272
|
createLocalMemoryClient,
|
|
261
273
|
createPersistor
|
|
262
274
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -9,10 +9,10 @@ var LocalStorage = class {
|
|
|
9
9
|
}
|
|
10
10
|
set(key, value, options) {
|
|
11
11
|
this.client.set(key, value);
|
|
12
|
-
if (options == null ? void 0 : options.
|
|
12
|
+
if (options == null ? void 0 : options.PX) {
|
|
13
13
|
setTimeout(() => {
|
|
14
14
|
this.client.delete(key);
|
|
15
|
-
}, options.
|
|
15
|
+
}, options.PX);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
del(key) {
|
|
@@ -109,7 +109,7 @@ var Persistor = class {
|
|
|
109
109
|
}
|
|
110
110
|
createOptions(ttl) {
|
|
111
111
|
if (ttl !== null && ttl !== void 0) {
|
|
112
|
-
return {
|
|
112
|
+
return { PX: Math.round(ttl) };
|
|
113
113
|
}
|
|
114
114
|
return {};
|
|
115
115
|
}
|
|
@@ -136,9 +136,19 @@ var Persistor = class {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
};
|
|
139
|
+
var _persistors = {};
|
|
139
140
|
var createPersistor = (redis) => {
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
if (redis) {
|
|
142
|
+
const key = JSON.stringify(redis);
|
|
143
|
+
if (!_persistors[key]) {
|
|
144
|
+
const persistor = new Persistor(redis);
|
|
145
|
+
}
|
|
146
|
+
return _persistors[key];
|
|
147
|
+
}
|
|
148
|
+
return new Persistor();
|
|
149
|
+
};
|
|
150
|
+
var clean = () => {
|
|
151
|
+
_persistors = {};
|
|
142
152
|
};
|
|
143
153
|
|
|
144
154
|
// src/promiseCache.ts
|
|
@@ -226,6 +236,7 @@ export {
|
|
|
226
236
|
LocalStorage,
|
|
227
237
|
Persistor,
|
|
228
238
|
PromiseCache,
|
|
239
|
+
clean,
|
|
229
240
|
createLocalMemoryClient,
|
|
230
241
|
createPersistor
|
|
231
242
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/promise-cache",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
"build": "tsup-node src/index.ts --format esm,cjs --dts",
|
|
13
13
|
"dev": "tsc --watch --noEmit",
|
|
14
14
|
"lint": "biome check .",
|
|
15
|
-
"test": "vitest --passWithNoTests --coverage",
|
|
15
|
+
"test": "vitest run --passWithNoTests --coverage",
|
|
16
16
|
"typecheck": "vitest --typecheck.only --passWithNoTests"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"tsconfig": "*"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"redis": "4.6.
|
|
22
|
+
"redis": "4.6.14"
|
|
23
23
|
}
|
|
24
24
|
}
|