1 | /// <reference types="node" />
|
2 | import { Readable } from "stream";
|
3 | interface Blob {
|
4 | }
|
5 | /**
|
6 | * A simple persistent key-value store. Used to implement {@link Limits.cache}
|
7 | * for {@link throttle}.
|
8 | * @remarks
|
9 | * Entries can be expired, but are not actually deleted individually. The entire
|
10 | * cache can be deleted at once. Hence this cache is useful for storing results
|
11 | * that are expensive to compute but do not change too often (e.g. the
|
12 | * node_modules folder from an 'npm install' where 'package.json' is not
|
13 | * expected to change too often).
|
14 | *
|
15 | * By default faast.js will use the directory `~/.faastjs` as a local cache to
|
16 | * store data such as pricing retrieved from cloud APIs, and garbage collection
|
17 | * information. This directory can be safely deleted if no faast.js instances
|
18 | * are running.
|
19 | * @public
|
20 | */
|
21 | export declare class PersistentCache {
|
22 | /**
|
23 | * The directory under the user's home directory that will be used to
|
24 | * store cached values. The directory will be created if it doesn't
|
25 | * exist.
|
26 | */
|
27 | readonly dirRelativeToHomeDir: string;
|
28 | /**
|
29 | * The age (in ms) after which a cached entry is invalid. Default:
|
30 | * `24*3600*1000` (1 day).
|
31 | */
|
32 | readonly expiration: number;
|
33 | private initialized;
|
34 | private initialize;
|
35 | /**
|
36 | * The directory on disk where cached values are stored.
|
37 | */
|
38 | readonly dir: string;
|
39 | /**
|
40 | * Construct a new persistent cache, typically used with {@link Limits} as
|
41 | * part of the arguments to {@link throttle}.
|
42 | * @param dirRelativeToHomeDir - The directory under the user's home
|
43 | * directory that will be used to store cached values. The directory will be
|
44 | * created if it doesn't exist.
|
45 | * @param expiration - The age (in ms) after which a cached entry is
|
46 | * invalid. Default: `24*3600*1000` (1 day).
|
47 | */
|
48 | constructor(
|
49 | /**
|
50 | * The directory under the user's home directory that will be used to
|
51 | * store cached values. The directory will be created if it doesn't
|
52 | * exist.
|
53 | */
|
54 | dirRelativeToHomeDir: string,
|
55 | /**
|
56 | * The age (in ms) after which a cached entry is invalid. Default:
|
57 | * `24*3600*1000` (1 day).
|
58 | */
|
59 | expiration?: number);
|
60 | /**
|
61 | * Retrieves the value previously set for the given key, or undefined if the
|
62 | * key is not found.
|
63 | */
|
64 | get(key: string): Promise<Buffer | undefined>;
|
65 | /**
|
66 | * Set the cache key to the given value.
|
67 | * @returns a Promise that resolves when the cache entry has been persisted.
|
68 | */
|
69 | set(key: string, value: Buffer | string | Uint8Array | Readable | Blob): Promise<void>;
|
70 | /**
|
71 | * Retrieve all keys stored in the cache, including expired entries.
|
72 | */
|
73 | entries(): Promise<string[]>;
|
74 | /**
|
75 | * Deletes all cached entries from disk.
|
76 | * @param leaveEmptyDir - If true, leave the cache directory in place after
|
77 | * deleting its contents. If false, the cache directory will be removed.
|
78 | * Default: `true`.
|
79 | */
|
80 | clear({ leaveEmptyDir }?: {
|
81 | leaveEmptyDir?: boolean | undefined;
|
82 | }): Promise<void>;
|
83 | }
|
84 | export declare const caches: {
|
85 | awsPrices: PersistentCache;
|
86 | googlePrices: PersistentCache;
|
87 | awsGc: PersistentCache;
|
88 | };
|
89 | export {};
|