flat-cache 6.1.21 → 6.1.23
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.cjs +466 -476
- package/dist/index.d.cts +215 -214
- package/dist/index.d.mts +256 -0
- package/dist/index.mjs +451 -0
- package/package.json +10 -11
- package/dist/index.d.ts +0 -255
- package/dist/index.js +0 -455
package/dist/index.d.cts
CHANGED
|
@@ -1,223 +1,224 @@
|
|
|
1
|
-
import { CacheableMemory } from
|
|
2
|
-
import { Hookified } from
|
|
1
|
+
import { CacheableMemory } from "cacheable";
|
|
2
|
+
import { Hookified } from "hookified";
|
|
3
3
|
|
|
4
|
+
//#region src/index.d.ts
|
|
4
5
|
type FlatCacheOptions = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
ttl?: number | string;
|
|
7
|
+
useClone?: boolean;
|
|
8
|
+
lruSize?: number;
|
|
9
|
+
expirationInterval?: number;
|
|
10
|
+
persistInterval?: number;
|
|
11
|
+
cacheDir?: string;
|
|
12
|
+
cacheId?: string;
|
|
13
|
+
deserialize?: (data: string) => any;
|
|
14
|
+
serialize?: (data: any) => string;
|
|
14
15
|
};
|
|
15
16
|
declare enum FlatCacheEvents {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
SAVE = "save",
|
|
18
|
+
LOAD = "load",
|
|
19
|
+
DELETE = "delete",
|
|
20
|
+
CLEAR = "clear",
|
|
21
|
+
DESTROY = "destroy",
|
|
22
|
+
ERROR = "error",
|
|
23
|
+
EXPIRED = "expired"
|
|
23
24
|
}
|
|
24
25
|
declare class FlatCache extends Hookified {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
26
|
+
private readonly _cache;
|
|
27
|
+
private _cacheDir;
|
|
28
|
+
private _cacheId;
|
|
29
|
+
private _persistInterval;
|
|
30
|
+
private _persistTimer;
|
|
31
|
+
private _changesSinceLastSave;
|
|
32
|
+
private readonly _parse;
|
|
33
|
+
private readonly _stringify;
|
|
34
|
+
constructor(options?: FlatCacheOptions);
|
|
35
|
+
/**
|
|
36
|
+
* The cache object
|
|
37
|
+
* @property cache
|
|
38
|
+
* @type {CacheableMemory}
|
|
39
|
+
*/
|
|
40
|
+
get cache(): CacheableMemory;
|
|
41
|
+
/**
|
|
42
|
+
* The cache directory
|
|
43
|
+
* @property cacheDir
|
|
44
|
+
* @type {String}
|
|
45
|
+
* @default '.cache'
|
|
46
|
+
*/
|
|
47
|
+
get cacheDir(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Set the cache directory
|
|
50
|
+
* @property cacheDir
|
|
51
|
+
* @type {String}
|
|
52
|
+
* @default '.cache'
|
|
53
|
+
*/
|
|
54
|
+
set cacheDir(value: string);
|
|
55
|
+
/**
|
|
56
|
+
* The cache id
|
|
57
|
+
* @property cacheId
|
|
58
|
+
* @type {String}
|
|
59
|
+
* @default 'cache1'
|
|
60
|
+
*/
|
|
61
|
+
get cacheId(): string;
|
|
62
|
+
/**
|
|
63
|
+
* Set the cache id
|
|
64
|
+
* @property cacheId
|
|
65
|
+
* @type {String}
|
|
66
|
+
* @default 'cache1'
|
|
67
|
+
*/
|
|
68
|
+
set cacheId(value: string);
|
|
69
|
+
/**
|
|
70
|
+
* The flag to indicate if there are changes since the last save
|
|
71
|
+
* @property changesSinceLastSave
|
|
72
|
+
* @type {Boolean}
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
get changesSinceLastSave(): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* The interval to persist the cache to disk. 0 means no timed persistence
|
|
78
|
+
* @property persistInterval
|
|
79
|
+
* @type {Number}
|
|
80
|
+
* @default 0
|
|
81
|
+
*/
|
|
82
|
+
get persistInterval(): number;
|
|
83
|
+
/**
|
|
84
|
+
* Set the interval to persist the cache to disk. 0 means no timed persistence
|
|
85
|
+
* @property persistInterval
|
|
86
|
+
* @type {Number}
|
|
87
|
+
* @default 0
|
|
88
|
+
*/
|
|
89
|
+
set persistInterval(value: number);
|
|
90
|
+
/**
|
|
91
|
+
* Load a cache identified by the given Id. If the element does not exists, then initialize an empty
|
|
92
|
+
* cache storage. If specified `cacheDir` will be used as the directory to persist the data to. If omitted
|
|
93
|
+
* then the cache module directory `.cacheDir` will be used instead
|
|
94
|
+
*
|
|
95
|
+
* @method load
|
|
96
|
+
* @param cacheId {String} the id of the cache, would also be used as the name of the file cache
|
|
97
|
+
* @param cacheDir {String} directory for the cache entry
|
|
98
|
+
*/
|
|
99
|
+
load(cacheId?: string, cacheDir?: string): void;
|
|
100
|
+
/**
|
|
101
|
+
* Load the cache from the provided file
|
|
102
|
+
* @method loadFile
|
|
103
|
+
* @param {String} pathToFile the path to the file containing the info for the cache
|
|
104
|
+
*/
|
|
105
|
+
loadFile(pathToFile: string): void;
|
|
106
|
+
loadFileStream(pathToFile: string, onProgress: (progress: number, total: number) => void, onEnd: () => void, onError?: (error: Error) => void): void;
|
|
107
|
+
/**
|
|
108
|
+
* Returns the entire persisted object
|
|
109
|
+
* @method all
|
|
110
|
+
* @returns {*}
|
|
111
|
+
*/
|
|
112
|
+
all(): Record<string, any>;
|
|
113
|
+
/**
|
|
114
|
+
* Returns an array with all the items in the cache { key, value, expires }
|
|
115
|
+
* @method items
|
|
116
|
+
* @returns {Array}
|
|
117
|
+
*/
|
|
118
|
+
get items(): Array<{
|
|
119
|
+
key: string;
|
|
120
|
+
value: any;
|
|
121
|
+
expires?: number;
|
|
122
|
+
}>;
|
|
123
|
+
/**
|
|
124
|
+
* Returns the path to the file where the cache is persisted
|
|
125
|
+
* @method cacheFilePath
|
|
126
|
+
* @returns {String}
|
|
127
|
+
*/
|
|
128
|
+
get cacheFilePath(): string;
|
|
129
|
+
/**
|
|
130
|
+
* Returns the path to the cache directory
|
|
131
|
+
* @method cacheDirPath
|
|
132
|
+
* @returns {String}
|
|
133
|
+
*/
|
|
134
|
+
get cacheDirPath(): string;
|
|
135
|
+
/**
|
|
136
|
+
* Returns an array with all the keys in the cache
|
|
137
|
+
* @method keys
|
|
138
|
+
* @returns {Array}
|
|
139
|
+
*/
|
|
140
|
+
keys(): string[];
|
|
141
|
+
/**
|
|
142
|
+
* (Legacy) set key method. This method will be deprecated in the future
|
|
143
|
+
* @method setKey
|
|
144
|
+
* @param key {string} the key to set
|
|
145
|
+
* @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
|
|
146
|
+
*/
|
|
147
|
+
setKey(key: string, value: any, ttl?: number | string): void;
|
|
148
|
+
/**
|
|
149
|
+
* Sets a key to a given value
|
|
150
|
+
* @method set
|
|
151
|
+
* @param key {string} the key to set
|
|
152
|
+
* @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
|
|
153
|
+
* @param [ttl] {number} the time to live in milliseconds
|
|
154
|
+
*/
|
|
155
|
+
set(key: string, value: any, ttl?: number | string): void;
|
|
156
|
+
/**
|
|
157
|
+
* (Legacy) Remove a given key from the cache. This method will be deprecated in the future
|
|
158
|
+
* @method removeKey
|
|
159
|
+
* @param key {String} the key to remove from the object
|
|
160
|
+
*/
|
|
161
|
+
removeKey(key: string): void;
|
|
162
|
+
/**
|
|
163
|
+
* Remove a given key from the cache
|
|
164
|
+
* @method delete
|
|
165
|
+
* @param key {String} the key to remove from the object
|
|
166
|
+
*/
|
|
167
|
+
delete(key: string): void;
|
|
168
|
+
/**
|
|
169
|
+
* (Legacy) Return the value of the provided key. This method will be deprecated in the future
|
|
170
|
+
* @method getKey<T>
|
|
171
|
+
* @param key {String} the name of the key to retrieve
|
|
172
|
+
* @returns {*} at T the value from the key
|
|
173
|
+
*/
|
|
174
|
+
getKey<T>(key: string): T;
|
|
175
|
+
/**
|
|
176
|
+
* Return the value of the provided key
|
|
177
|
+
* @method get<T>
|
|
178
|
+
* @param key {String} the name of the key to retrieve
|
|
179
|
+
* @returns {*} at T the value from the key
|
|
180
|
+
*/
|
|
181
|
+
get<T>(key: string): T;
|
|
182
|
+
/**
|
|
183
|
+
* Clear the cache and save the state to disk
|
|
184
|
+
* @method clear
|
|
185
|
+
*/
|
|
186
|
+
clear(): void;
|
|
187
|
+
/**
|
|
188
|
+
* Save the state of the cache identified by the docId to disk
|
|
189
|
+
* as a JSON structure
|
|
190
|
+
* @method save
|
|
191
|
+
*/
|
|
192
|
+
save(force?: boolean): void;
|
|
193
|
+
/**
|
|
194
|
+
* Remove the file where the cache is persisted
|
|
195
|
+
* @method removeCacheFile
|
|
196
|
+
* @return {Boolean} true or false if the file was successfully deleted
|
|
197
|
+
*/
|
|
198
|
+
removeCacheFile(): boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Destroy the cache. This will remove the directory, file, and memory cache
|
|
201
|
+
* @method destroy
|
|
202
|
+
* @param [includeCacheDir=false] {Boolean} if true, the cache directory will be removed
|
|
203
|
+
* @return {undefined}
|
|
204
|
+
*/
|
|
205
|
+
destroy(includeCacheDirectory?: boolean): void;
|
|
206
|
+
/**
|
|
207
|
+
* Start the auto persist interval
|
|
208
|
+
* @method startAutoPersist
|
|
209
|
+
*/
|
|
210
|
+
startAutoPersist(): void;
|
|
211
|
+
/**
|
|
212
|
+
* Stop the auto persist interval
|
|
213
|
+
* @method stopAutoPersist
|
|
214
|
+
*/
|
|
215
|
+
stopAutoPersist(): void;
|
|
215
216
|
}
|
|
216
217
|
declare class FlatCacheDefault {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
218
|
+
static create: typeof create;
|
|
219
|
+
static createFromFile: typeof createFromFile;
|
|
220
|
+
static clearCacheById: typeof clearCacheById;
|
|
221
|
+
static clearAll: typeof clearAll;
|
|
221
222
|
}
|
|
222
223
|
/**
|
|
223
224
|
* Load a cache identified by the given Id. If the element does not exists, then initialize an empty
|
|
@@ -251,5 +252,5 @@ declare function clearCacheById(cacheId: string, cacheDirectory?: string): void;
|
|
|
251
252
|
* @param cacheDir {String} directory for the cache entry
|
|
252
253
|
*/
|
|
253
254
|
declare function clearAll(cacheDirectory?: string): void;
|
|
254
|
-
|
|
255
|
-
export { FlatCache, FlatCacheEvents,
|
|
255
|
+
//#endregion
|
|
256
|
+
export { FlatCache, FlatCacheEvents, FlatCacheOptions, clearAll, clearCacheById, create, createFromFile, FlatCacheDefault as default };
|