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