Repository navigation
Expand file tree
/
Copy pathindex.d.mts
More file actions
256 lines (255 loc) · 7.6 KB
/
Copy pathindex.d.mts
File metadata and controls
256 lines (255 loc) · 7.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import { CacheableMemory } from "cacheable";
import { Hookified } from "hookified";
//#region src/index.d.ts
type FlatCacheOptions = {
ttl?: number | string;
useClone?: boolean;
lruSize?: number;
expirationInterval?: number;
persistInterval?: number;
cacheDir?: string;
cacheId?: string;
deserialize?: (data: string) => any;
serialize?: (data: any) => string;
};
declare enum FlatCacheEvents {
SAVE = "save",
LOAD = "load",
DELETE = "delete",
CLEAR = "clear",
DESTROY = "destroy",
ERROR = "error",
EXPIRED = "expired"
}
declare class FlatCache extends Hookified {
private readonly _cache;
private _cacheDir;
private _cacheId;
private _persistInterval;
private _persistTimer;
private _changesSinceLastSave;
private readonly _parse;
private readonly _stringify;
constructor(options?: FlatCacheOptions);
/**
* The cache object
* @property cache
* @type {CacheableMemory}
*/
get cache(): CacheableMemory;
/**
* The cache directory
* @property cacheDir
* @type {String}
* @default '.cache'
*/
get cacheDir(): string;
/**
* Set the cache directory
* @property cacheDir
* @type {String}
* @default '.cache'
*/
set cacheDir(value: string);
/**
* The cache id
* @property cacheId
* @type {String}
* @default 'cache1'
*/
get cacheId(): string;
/**
* Set the cache id
* @property cacheId
* @type {String}
* @default 'cache1'
*/
set cacheId(value: string);
/**
* The flag to indicate if there are changes since the last save
* @property changesSinceLastSave
* @type {Boolean}
* @default false
*/
get changesSinceLastSave(): boolean;
/**
* The interval to persist the cache to disk. 0 means no timed persistence
* @property persistInterval
* @type {Number}
* @default 0
*/
get persistInterval(): number;
/**
* Set the interval to persist the cache to disk. 0 means no timed persistence
* @property persistInterval
* @type {Number}
* @default 0
*/
set persistInterval(value: number);
/**
* Load a cache identified by the given Id. If the element does not exists, then initialize an empty
* cache storage. If specified `cacheDir` will be used as the directory to persist the data to. If omitted
* then the cache module directory `.cacheDir` will be used instead
*
* @method load
* @param cacheId {String} the id of the cache, would also be used as the name of the file cache
* @param cacheDir {String} directory for the cache entry
*/
load(cacheId?: string, cacheDir?: string): void;
/**
* Load the cache from the provided file
* @method loadFile
* @param {String} pathToFile the path to the file containing the info for the cache
*/
loadFile(pathToFile: string): void;
loadFileStream(pathToFile: string, onProgress: (progress: number, total: number) => void, onEnd: () => void, onError?: (error: Error) => void): void;
/**
* Returns the entire persisted object
* @method all
* @returns {*}
*/
all(): Record<string, any>;
/**
* Returns an array with all the items in the cache { key, value, expires }
* @method items
* @returns {Array}
*/
get items(): Array<{
key: string;
value: any;
expires?: number;
}>;
/**
* Returns the path to the file where the cache is persisted
* @method cacheFilePath
* @returns {String}
*/
get cacheFilePath(): string;
/**
* Returns the path to the cache directory
* @method cacheDirPath
* @returns {String}
*/
get cacheDirPath(): string;
/**
* Returns an array with all the keys in the cache
* @method keys
* @returns {Array}
*/
keys(): string[];
/**
* (Legacy) set key method. This method will be deprecated in the future
* @method setKey
* @param key {string} the key to set
* @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
*/
setKey(key: string, value: any, ttl?: number | string): void;
/**
* Sets a key to a given value
* @method set
* @param key {string} the key to set
* @param value {object} the value of the key. Could be any object that can be serialized with JSON.stringify
* @param [ttl] {number} the time to live in milliseconds
*/
set(key: string, value: any, ttl?: number | string): void;
/**
* (Legacy) Remove a given key from the cache. This method will be deprecated in the future
* @method removeKey
* @param key {String} the key to remove from the object
*/
removeKey(key: string): void;
/**
* Remove a given key from the cache
* @method delete
* @param key {String} the key to remove from the object
*/
delete(key: string): void;
/**
* (Legacy) Return the value of the provided key. This method will be deprecated in the future
* @method getKey<T>
* @param key {String} the name of the key to retrieve
* @returns {*} at T the value from the key
*/
getKey<T>(key: string): T;
/**
* Return the value of the provided key
* @method get<T>
* @param key {String} the name of the key to retrieve
* @returns {*} at T the value from the key
*/
get<T>(key: string): T;
/**
* Clear the cache and save the state to disk
* @method clear
*/
clear(): void;
/**
* Save the state of the cache identified by the docId to disk
* as a JSON structure
* @method save
*/
save(force?: boolean): void;
/**
* Remove the file where the cache is persisted
* @method removeCacheFile
* @return {Boolean} true or false if the file was successfully deleted
*/
removeCacheFile(): boolean;
/**
* Destroy the cache. This will remove the directory, file, and memory cache
* @method destroy
* @param [includeCacheDir=false] {Boolean} if true, the cache directory will be removed
* @return {undefined}
*/
destroy(includeCacheDirectory?: boolean): void;
/**
* Start the auto persist interval
* @method startAutoPersist
*/
startAutoPersist(): void;
/**
* Stop the auto persist interval
* @method stopAutoPersist
*/
stopAutoPersist(): void;
}
declare class FlatCacheDefault {
static create: typeof create;
static createFromFile: typeof createFromFile;
static clearCacheById: typeof clearCacheById;
static clearAll: typeof clearAll;
}
/**
* Load a cache identified by the given Id. If the element does not exists, then initialize an empty
* cache storage.
*
* @method create
* @param docId {String} the id of the cache, would also be used as the name of the file cache
* @param cacheDirectory {String} directory for the cache entry
* @param options {FlatCacheOptions} options for the cache
* @returns {cache} cache instance
*/
declare function create(options?: FlatCacheOptions): FlatCache;
/**
* Load a cache from the provided file
* @method createFromFile
* @param {String} filePath the path to the file containing the info for the cache
* @param options {FlatCacheOptions} options for the cache
* @returns {cache} cache instance
*/
declare function createFromFile(filePath: string, options?: FlatCacheOptions): FlatCache;
/**
* Clear the cache identified by the given Id. This will only remove the cache from disk.
* @method clearCacheById
* @param cacheId {String} the id of the cache
* @param cacheDirectory {String} directory for the cache entry
*/
declare function clearCacheById(cacheId: string, cacheDirectory?: string): void;
/**
* Clear the cache directory
* @method clearAll
* @param cacheDir {String} directory for the cache entry
*/
declare function clearAll(cacheDirectory?: string): void;
//#endregion
export { FlatCache, FlatCacheEvents, FlatCacheOptions, clearAll, clearCacheById, create, createFromFile, FlatCacheDefault as default };