@sebspark/promise-cache 0.2.3 → 0.2.5
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/README.md +8 -2
- package/dist/index.d.mts +14 -10
- package/dist/index.d.ts +14 -10
- package/dist/index.js +72 -46
- package/dist/index.mjs +70 -45
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,9 +9,15 @@ A simple caching wrapper for promises.
|
|
|
9
9
|
import { PromiseCache } from '@sebspark/promise-cache'
|
|
10
10
|
|
|
11
11
|
// Instantiate the cache with a TTL.
|
|
12
|
-
const cache = new PromiseCache<
|
|
12
|
+
const cache = new PromiseCache<number>(60, true, true) // 1 minute cache TTL / is case sensitive / use local storage
|
|
13
|
+
|
|
14
|
+
const redisCache = new PromiseCache<number>(60, false, false) // 1 minute cache TTL / is not case sensitive / use redis storage
|
|
13
15
|
|
|
14
16
|
// Use the cache wrapper for a database query to relieve the database.
|
|
15
17
|
const query = 'SELECT username FROM users ORDER BY created DESC LIMIT 1'
|
|
16
18
|
const newestUser = await cache.wrap('newestUser', () => database.query(query))
|
|
17
|
-
|
|
19
|
+
|
|
20
|
+
// Use the cache wrapper for a database query to relieve the database.
|
|
21
|
+
const query = 'SELECT username FROM users ORDER BY created DESC LIMIT 1'
|
|
22
|
+
const newestUser = await redisCache.wrap('newestUserRedis', () => database.query(query))
|
|
23
|
+
```
|
package/dist/index.d.mts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
+
import { createClient } from 'redis';
|
|
2
|
+
|
|
1
3
|
type GetType<T> = {
|
|
2
4
|
value: T;
|
|
3
|
-
ttl
|
|
5
|
+
ttl?: number;
|
|
4
6
|
timestamp: number;
|
|
5
7
|
};
|
|
6
8
|
type SetParams<T> = {
|
|
7
9
|
value: T;
|
|
8
10
|
timestamp: number;
|
|
9
|
-
ttl
|
|
11
|
+
ttl?: number;
|
|
10
12
|
};
|
|
11
13
|
declare class Persistor {
|
|
12
|
-
|
|
14
|
+
client: ReturnType<typeof createClient> | null;
|
|
13
15
|
status: 'connected' | 'disconnected';
|
|
14
|
-
constructor();
|
|
16
|
+
constructor(isLocalPersistor: boolean);
|
|
15
17
|
connect(): Promise<void>;
|
|
16
18
|
size(): Promise<number>;
|
|
17
19
|
get<T>(key: string): Promise<GetType<T> | null>;
|
|
20
|
+
private createOptions;
|
|
18
21
|
set<T>(key: string, { value, timestamp, ttl }: SetParams<T>): Promise<void>;
|
|
19
22
|
delete(key: string): Promise<void>;
|
|
20
23
|
}
|
|
@@ -22,13 +25,13 @@ declare class Persistor {
|
|
|
22
25
|
declare class PromiseCache<U> {
|
|
23
26
|
persistor: Persistor;
|
|
24
27
|
private readonly caseSensitive;
|
|
25
|
-
private readonly ttl
|
|
28
|
+
private readonly ttl?;
|
|
26
29
|
/**
|
|
27
30
|
* Initialize a new PromiseCache.
|
|
28
31
|
* @param ttlInSeconds Default cache TTL.
|
|
29
32
|
* @param caseSensitive Set to true if you want to differentiate between keys with different casing.
|
|
30
33
|
*/
|
|
31
|
-
constructor(ttlInSeconds
|
|
34
|
+
constructor(ttlInSeconds?: number, caseSensitive?: boolean, isLocalPersistor?: boolean);
|
|
32
35
|
/**
|
|
33
36
|
* Cache size.
|
|
34
37
|
* @returns The number of entries in the cache.
|
|
@@ -56,17 +59,18 @@ declare class PromiseCache<U> {
|
|
|
56
59
|
wrap(key: string, delegate: () => Promise<U>, ttlInSeconds?: number): Promise<U>;
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
declare class
|
|
62
|
+
declare class LocalStorage {
|
|
60
63
|
client: Map<any, any>;
|
|
61
64
|
get(key: string): any;
|
|
62
65
|
set(key: string, value: string, options?: {
|
|
63
66
|
EX: number;
|
|
64
67
|
}): void;
|
|
68
|
+
del(key: string): void;
|
|
65
69
|
clear(): void;
|
|
66
70
|
DBSIZE(): Promise<number>;
|
|
67
|
-
on(event: string, callback: () => void): this;
|
|
71
|
+
on(event: string, callback: (message: string) => void): this;
|
|
68
72
|
connect(): Promise<this>;
|
|
69
73
|
}
|
|
70
|
-
declare const
|
|
74
|
+
declare const createLocalMemoryClient: () => LocalStorage;
|
|
71
75
|
|
|
72
|
-
export { PromiseCache,
|
|
76
|
+
export { LocalStorage, PromiseCache, createLocalMemoryClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
+
import { createClient } from 'redis';
|
|
2
|
+
|
|
1
3
|
type GetType<T> = {
|
|
2
4
|
value: T;
|
|
3
|
-
ttl
|
|
5
|
+
ttl?: number;
|
|
4
6
|
timestamp: number;
|
|
5
7
|
};
|
|
6
8
|
type SetParams<T> = {
|
|
7
9
|
value: T;
|
|
8
10
|
timestamp: number;
|
|
9
|
-
ttl
|
|
11
|
+
ttl?: number;
|
|
10
12
|
};
|
|
11
13
|
declare class Persistor {
|
|
12
|
-
|
|
14
|
+
client: ReturnType<typeof createClient> | null;
|
|
13
15
|
status: 'connected' | 'disconnected';
|
|
14
|
-
constructor();
|
|
16
|
+
constructor(isLocalPersistor: boolean);
|
|
15
17
|
connect(): Promise<void>;
|
|
16
18
|
size(): Promise<number>;
|
|
17
19
|
get<T>(key: string): Promise<GetType<T> | null>;
|
|
20
|
+
private createOptions;
|
|
18
21
|
set<T>(key: string, { value, timestamp, ttl }: SetParams<T>): Promise<void>;
|
|
19
22
|
delete(key: string): Promise<void>;
|
|
20
23
|
}
|
|
@@ -22,13 +25,13 @@ declare class Persistor {
|
|
|
22
25
|
declare class PromiseCache<U> {
|
|
23
26
|
persistor: Persistor;
|
|
24
27
|
private readonly caseSensitive;
|
|
25
|
-
private readonly ttl
|
|
28
|
+
private readonly ttl?;
|
|
26
29
|
/**
|
|
27
30
|
* Initialize a new PromiseCache.
|
|
28
31
|
* @param ttlInSeconds Default cache TTL.
|
|
29
32
|
* @param caseSensitive Set to true if you want to differentiate between keys with different casing.
|
|
30
33
|
*/
|
|
31
|
-
constructor(ttlInSeconds
|
|
34
|
+
constructor(ttlInSeconds?: number, caseSensitive?: boolean, isLocalPersistor?: boolean);
|
|
32
35
|
/**
|
|
33
36
|
* Cache size.
|
|
34
37
|
* @returns The number of entries in the cache.
|
|
@@ -56,17 +59,18 @@ declare class PromiseCache<U> {
|
|
|
56
59
|
wrap(key: string, delegate: () => Promise<U>, ttlInSeconds?: number): Promise<U>;
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
declare class
|
|
62
|
+
declare class LocalStorage {
|
|
60
63
|
client: Map<any, any>;
|
|
61
64
|
get(key: string): any;
|
|
62
65
|
set(key: string, value: string, options?: {
|
|
63
66
|
EX: number;
|
|
64
67
|
}): void;
|
|
68
|
+
del(key: string): void;
|
|
65
69
|
clear(): void;
|
|
66
70
|
DBSIZE(): Promise<number>;
|
|
67
|
-
on(event: string, callback: () => void): this;
|
|
71
|
+
on(event: string, callback: (message: string) => void): this;
|
|
68
72
|
connect(): Promise<this>;
|
|
69
73
|
}
|
|
70
|
-
declare const
|
|
74
|
+
declare const createLocalMemoryClient: () => LocalStorage;
|
|
71
75
|
|
|
72
|
-
export { PromiseCache,
|
|
76
|
+
export { LocalStorage, PromiseCache, createLocalMemoryClient };
|
package/dist/index.js
CHANGED
|
@@ -20,25 +20,73 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
+
LocalStorage: () => LocalStorage,
|
|
23
24
|
PromiseCache: () => PromiseCache,
|
|
24
|
-
|
|
25
|
+
createLocalMemoryClient: () => createLocalMemoryClient
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(src_exports);
|
|
27
28
|
|
|
28
29
|
// src/persistor.ts
|
|
29
30
|
var import_redis = require("redis");
|
|
31
|
+
|
|
32
|
+
// src/localMemory.ts
|
|
33
|
+
var LocalStorage = class {
|
|
34
|
+
client = /* @__PURE__ */ new Map();
|
|
35
|
+
get(key) {
|
|
36
|
+
return this.client.get(key);
|
|
37
|
+
}
|
|
38
|
+
set(key, value, options) {
|
|
39
|
+
this.client.set(key, value);
|
|
40
|
+
if (options == null ? void 0 : options.EX) {
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
this.client.delete(key);
|
|
43
|
+
}, options.EX / 1e3);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
del(key) {
|
|
47
|
+
this.client.delete(key);
|
|
48
|
+
}
|
|
49
|
+
clear() {
|
|
50
|
+
this.client.clear();
|
|
51
|
+
}
|
|
52
|
+
async DBSIZE() {
|
|
53
|
+
return Promise.resolve(this.client.size);
|
|
54
|
+
}
|
|
55
|
+
// This is just for testing
|
|
56
|
+
on(event, callback) {
|
|
57
|
+
if (event === "connect") {
|
|
58
|
+
callback("connect");
|
|
59
|
+
}
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
connect() {
|
|
63
|
+
return Promise.resolve(this);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var createLocalMemoryClient = () => {
|
|
67
|
+
return new LocalStorage();
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/persistor.ts
|
|
30
71
|
var REDIS_HOST = process.env.REDIS_HOST || "127.0.0.1";
|
|
31
72
|
var REDIS_PORT = process.env.REDIS_PORT || 6379;
|
|
32
73
|
var REDIS_URL = `redis://${REDIS_HOST}:${REDIS_PORT}`;
|
|
74
|
+
var CACHE_CLIENT = import_redis.createClient;
|
|
75
|
+
if (process.env.JEST_WORKER_ID) {
|
|
76
|
+
CACHE_CLIENT = createLocalMemoryClient;
|
|
77
|
+
}
|
|
33
78
|
var Persistor = class {
|
|
34
|
-
client;
|
|
79
|
+
client = null;
|
|
35
80
|
status = "disconnected";
|
|
36
|
-
constructor() {
|
|
81
|
+
constructor(isLocalPersistor) {
|
|
82
|
+
if (isLocalPersistor) {
|
|
83
|
+
CACHE_CLIENT = createLocalMemoryClient;
|
|
84
|
+
}
|
|
37
85
|
this.connect();
|
|
38
86
|
}
|
|
39
87
|
async connect() {
|
|
40
88
|
try {
|
|
41
|
-
this.client = (
|
|
89
|
+
this.client = CACHE_CLIENT({ url: REDIS_URL });
|
|
42
90
|
this.client.on("error", (err) => {
|
|
43
91
|
console.error(`\u274C REDIS | Client Error | ${REDIS_URL}`, err);
|
|
44
92
|
this.status = "disconnected";
|
|
@@ -50,7 +98,7 @@ var Persistor = class {
|
|
|
50
98
|
return;
|
|
51
99
|
}
|
|
52
100
|
this.client.on("connect", () => {
|
|
53
|
-
console.
|
|
101
|
+
console.log(`\u{1F4E6} REDIS | Connection Ready | ${REDIS_URL}`);
|
|
54
102
|
this.status = "connected";
|
|
55
103
|
resolve(true);
|
|
56
104
|
});
|
|
@@ -81,15 +129,20 @@ var Persistor = class {
|
|
|
81
129
|
throw error;
|
|
82
130
|
}
|
|
83
131
|
}
|
|
132
|
+
createOptions(ttl) {
|
|
133
|
+
if (ttl !== null && ttl !== void 0) {
|
|
134
|
+
return { EX: ttl / 1e3 };
|
|
135
|
+
}
|
|
136
|
+
return {};
|
|
137
|
+
}
|
|
84
138
|
async set(key, { value, timestamp, ttl }) {
|
|
85
139
|
if (!this.client) {
|
|
86
140
|
throw new Error("Client not initialized");
|
|
87
141
|
}
|
|
88
142
|
try {
|
|
89
143
|
const serializedData = JSON.stringify({ value, ttl, timestamp });
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
144
|
+
const options = this.createOptions(ttl);
|
|
145
|
+
await this.client.set(key, serializedData, options);
|
|
93
146
|
} catch (error) {
|
|
94
147
|
console.error(`Error setting data in redis: ${error}`);
|
|
95
148
|
throw error;
|
|
@@ -107,7 +160,10 @@ var Persistor = class {
|
|
|
107
160
|
}
|
|
108
161
|
}
|
|
109
162
|
};
|
|
110
|
-
var
|
|
163
|
+
var createPersistor = (isLocalPersistor) => {
|
|
164
|
+
const persistor = new Persistor(isLocalPersistor);
|
|
165
|
+
return persistor;
|
|
166
|
+
};
|
|
111
167
|
|
|
112
168
|
// src/promiseCache.ts
|
|
113
169
|
var PromiseCache = class {
|
|
@@ -120,10 +176,12 @@ var PromiseCache = class {
|
|
|
120
176
|
* @param ttlInSeconds Default cache TTL.
|
|
121
177
|
* @param caseSensitive Set to true if you want to differentiate between keys with different casing.
|
|
122
178
|
*/
|
|
123
|
-
constructor(ttlInSeconds, caseSensitive = false) {
|
|
124
|
-
this.persistor =
|
|
179
|
+
constructor(ttlInSeconds, caseSensitive = false, isLocalPersistor = false) {
|
|
180
|
+
this.persistor = createPersistor(isLocalPersistor);
|
|
125
181
|
this.caseSensitive = caseSensitive;
|
|
126
|
-
|
|
182
|
+
if (ttlInSeconds) {
|
|
183
|
+
this.ttl = ttlInSeconds * 1e3;
|
|
184
|
+
}
|
|
127
185
|
}
|
|
128
186
|
/**
|
|
129
187
|
* Cache size.
|
|
@@ -184,41 +242,9 @@ var PromiseCache = class {
|
|
|
184
242
|
return response;
|
|
185
243
|
}
|
|
186
244
|
};
|
|
187
|
-
|
|
188
|
-
// src/test/mockedRedis.ts
|
|
189
|
-
var MockedRedis = class {
|
|
190
|
-
client = /* @__PURE__ */ new Map();
|
|
191
|
-
get(key) {
|
|
192
|
-
return this.client.get(key);
|
|
193
|
-
}
|
|
194
|
-
set(key, value, options) {
|
|
195
|
-
this.client.set(key, value);
|
|
196
|
-
if (options == null ? void 0 : options.EX) {
|
|
197
|
-
setTimeout(() => {
|
|
198
|
-
this.client.delete(key);
|
|
199
|
-
}, options.EX / 1e3);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
clear() {
|
|
203
|
-
this.client.clear();
|
|
204
|
-
}
|
|
205
|
-
async DBSIZE() {
|
|
206
|
-
return Promise.resolve(this.client.size);
|
|
207
|
-
}
|
|
208
|
-
// Fake connection to fake server
|
|
209
|
-
on(event, callback) {
|
|
210
|
-
if (event === "connect") {
|
|
211
|
-
callback();
|
|
212
|
-
}
|
|
213
|
-
return this;
|
|
214
|
-
}
|
|
215
|
-
connect() {
|
|
216
|
-
return Promise.resolve(this);
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
var createClient2 = () => new MockedRedis();
|
|
220
245
|
// Annotate the CommonJS export names for ESM import in node:
|
|
221
246
|
0 && (module.exports = {
|
|
247
|
+
LocalStorage,
|
|
222
248
|
PromiseCache,
|
|
223
|
-
|
|
249
|
+
createLocalMemoryClient
|
|
224
250
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,64 @@
|
|
|
1
1
|
// src/persistor.ts
|
|
2
2
|
import { createClient } from "redis";
|
|
3
|
+
|
|
4
|
+
// src/localMemory.ts
|
|
5
|
+
var LocalStorage = class {
|
|
6
|
+
client = /* @__PURE__ */ new Map();
|
|
7
|
+
get(key) {
|
|
8
|
+
return this.client.get(key);
|
|
9
|
+
}
|
|
10
|
+
set(key, value, options) {
|
|
11
|
+
this.client.set(key, value);
|
|
12
|
+
if (options == null ? void 0 : options.EX) {
|
|
13
|
+
setTimeout(() => {
|
|
14
|
+
this.client.delete(key);
|
|
15
|
+
}, options.EX / 1e3);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
del(key) {
|
|
19
|
+
this.client.delete(key);
|
|
20
|
+
}
|
|
21
|
+
clear() {
|
|
22
|
+
this.client.clear();
|
|
23
|
+
}
|
|
24
|
+
async DBSIZE() {
|
|
25
|
+
return Promise.resolve(this.client.size);
|
|
26
|
+
}
|
|
27
|
+
// This is just for testing
|
|
28
|
+
on(event, callback) {
|
|
29
|
+
if (event === "connect") {
|
|
30
|
+
callback("connect");
|
|
31
|
+
}
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
connect() {
|
|
35
|
+
return Promise.resolve(this);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var createLocalMemoryClient = () => {
|
|
39
|
+
return new LocalStorage();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/persistor.ts
|
|
3
43
|
var REDIS_HOST = process.env.REDIS_HOST || "127.0.0.1";
|
|
4
44
|
var REDIS_PORT = process.env.REDIS_PORT || 6379;
|
|
5
45
|
var REDIS_URL = `redis://${REDIS_HOST}:${REDIS_PORT}`;
|
|
46
|
+
var CACHE_CLIENT = createClient;
|
|
47
|
+
if (process.env.JEST_WORKER_ID) {
|
|
48
|
+
CACHE_CLIENT = createLocalMemoryClient;
|
|
49
|
+
}
|
|
6
50
|
var Persistor = class {
|
|
7
|
-
client;
|
|
51
|
+
client = null;
|
|
8
52
|
status = "disconnected";
|
|
9
|
-
constructor() {
|
|
53
|
+
constructor(isLocalPersistor) {
|
|
54
|
+
if (isLocalPersistor) {
|
|
55
|
+
CACHE_CLIENT = createLocalMemoryClient;
|
|
56
|
+
}
|
|
10
57
|
this.connect();
|
|
11
58
|
}
|
|
12
59
|
async connect() {
|
|
13
60
|
try {
|
|
14
|
-
this.client =
|
|
61
|
+
this.client = CACHE_CLIENT({ url: REDIS_URL });
|
|
15
62
|
this.client.on("error", (err) => {
|
|
16
63
|
console.error(`\u274C REDIS | Client Error | ${REDIS_URL}`, err);
|
|
17
64
|
this.status = "disconnected";
|
|
@@ -23,7 +70,7 @@ var Persistor = class {
|
|
|
23
70
|
return;
|
|
24
71
|
}
|
|
25
72
|
this.client.on("connect", () => {
|
|
26
|
-
console.
|
|
73
|
+
console.log(`\u{1F4E6} REDIS | Connection Ready | ${REDIS_URL}`);
|
|
27
74
|
this.status = "connected";
|
|
28
75
|
resolve(true);
|
|
29
76
|
});
|
|
@@ -54,15 +101,20 @@ var Persistor = class {
|
|
|
54
101
|
throw error;
|
|
55
102
|
}
|
|
56
103
|
}
|
|
104
|
+
createOptions(ttl) {
|
|
105
|
+
if (ttl !== null && ttl !== void 0) {
|
|
106
|
+
return { EX: ttl / 1e3 };
|
|
107
|
+
}
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
57
110
|
async set(key, { value, timestamp, ttl }) {
|
|
58
111
|
if (!this.client) {
|
|
59
112
|
throw new Error("Client not initialized");
|
|
60
113
|
}
|
|
61
114
|
try {
|
|
62
115
|
const serializedData = JSON.stringify({ value, ttl, timestamp });
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
116
|
+
const options = this.createOptions(ttl);
|
|
117
|
+
await this.client.set(key, serializedData, options);
|
|
66
118
|
} catch (error) {
|
|
67
119
|
console.error(`Error setting data in redis: ${error}`);
|
|
68
120
|
throw error;
|
|
@@ -80,7 +132,10 @@ var Persistor = class {
|
|
|
80
132
|
}
|
|
81
133
|
}
|
|
82
134
|
};
|
|
83
|
-
var
|
|
135
|
+
var createPersistor = (isLocalPersistor) => {
|
|
136
|
+
const persistor = new Persistor(isLocalPersistor);
|
|
137
|
+
return persistor;
|
|
138
|
+
};
|
|
84
139
|
|
|
85
140
|
// src/promiseCache.ts
|
|
86
141
|
var PromiseCache = class {
|
|
@@ -93,10 +148,12 @@ var PromiseCache = class {
|
|
|
93
148
|
* @param ttlInSeconds Default cache TTL.
|
|
94
149
|
* @param caseSensitive Set to true if you want to differentiate between keys with different casing.
|
|
95
150
|
*/
|
|
96
|
-
constructor(ttlInSeconds, caseSensitive = false) {
|
|
97
|
-
this.persistor =
|
|
151
|
+
constructor(ttlInSeconds, caseSensitive = false, isLocalPersistor = false) {
|
|
152
|
+
this.persistor = createPersistor(isLocalPersistor);
|
|
98
153
|
this.caseSensitive = caseSensitive;
|
|
99
|
-
|
|
154
|
+
if (ttlInSeconds) {
|
|
155
|
+
this.ttl = ttlInSeconds * 1e3;
|
|
156
|
+
}
|
|
100
157
|
}
|
|
101
158
|
/**
|
|
102
159
|
* Cache size.
|
|
@@ -157,40 +214,8 @@ var PromiseCache = class {
|
|
|
157
214
|
return response;
|
|
158
215
|
}
|
|
159
216
|
};
|
|
160
|
-
|
|
161
|
-
// src/test/mockedRedis.ts
|
|
162
|
-
var MockedRedis = class {
|
|
163
|
-
client = /* @__PURE__ */ new Map();
|
|
164
|
-
get(key) {
|
|
165
|
-
return this.client.get(key);
|
|
166
|
-
}
|
|
167
|
-
set(key, value, options) {
|
|
168
|
-
this.client.set(key, value);
|
|
169
|
-
if (options == null ? void 0 : options.EX) {
|
|
170
|
-
setTimeout(() => {
|
|
171
|
-
this.client.delete(key);
|
|
172
|
-
}, options.EX / 1e3);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
clear() {
|
|
176
|
-
this.client.clear();
|
|
177
|
-
}
|
|
178
|
-
async DBSIZE() {
|
|
179
|
-
return Promise.resolve(this.client.size);
|
|
180
|
-
}
|
|
181
|
-
// Fake connection to fake server
|
|
182
|
-
on(event, callback) {
|
|
183
|
-
if (event === "connect") {
|
|
184
|
-
callback();
|
|
185
|
-
}
|
|
186
|
-
return this;
|
|
187
|
-
}
|
|
188
|
-
connect() {
|
|
189
|
-
return Promise.resolve(this);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
var createClient2 = () => new MockedRedis();
|
|
193
217
|
export {
|
|
218
|
+
LocalStorage,
|
|
194
219
|
PromiseCache,
|
|
195
|
-
|
|
220
|
+
createLocalMemoryClient
|
|
196
221
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/promise-cache",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -17,6 +17,6 @@
|
|
|
17
17
|
"tsconfig": "*"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"redis": "
|
|
20
|
+
"redis": "4.6.12"
|
|
21
21
|
}
|
|
22
22
|
}
|