1 | export = RandomOrgCache;
|
2 | declare class RandomOrgCache {
|
3 | /**
|
4 | * Initialize class and start stack population
|
5 | *
|
6 | * ** WARNING** Should only be called by RandomOrgClient's createCache()
|
7 | * methods.
|
8 | * @param {function(Object) : Object} requestFunction Function used to send
|
9 | * supplied request to server.
|
10 | * @param {Object} request Request to send to server via requestFunction.
|
11 | * @param {number} cacheSize Number of request responses to try maintain.
|
12 | * @param {number} bulkRequestNumber If request is set to be issued in bulk,
|
13 | * number of result sets in a bulk request, else 0.
|
14 | * @param {number} requestNumber If request is set to be issued in bulk,
|
15 | * number of results in a single request, else 0.
|
16 | * @param {number} singleRequestSize Size of a single request in bits for
|
17 | * adjusting bulk requests if bits are in short supply on the server.
|
18 | */
|
19 | constructor(requestFunction: (arg0: any) => any, request: any, cacheSize: number, bulkRequestNumber: number, requestNumber: number, singleRequestSize: number);
|
20 | /**
|
21 | * The cache will no longer continue to populate itself.
|
22 | */
|
23 | stop(): void;
|
24 | /**
|
25 | * The cache will resume populating itself if stopped.
|
26 | */
|
27 | resume(): void;
|
28 | /**
|
29 | * Checks if the cache is currently not re-populating itself.
|
30 | *
|
31 | * Values currently cached may still be retrieved with get() but no new
|
32 | * values are being fetched from the server. This state can be changed with
|
33 | * stop() and resume().
|
34 | * @returns {boolean} True if cache is currently not re-populating itself,
|
35 | * false otherwise.
|
36 | */
|
37 | isPaused(): boolean;
|
38 | /**
|
39 | * Gets the next response.
|
40 | * Note that if the cache is empty, if was constructed with unsuitable parameter
|
41 | * values or if the daily allowance of bits/requests has been reached, the appropriate
|
42 | * error will be thrown.
|
43 | * @returns {any[]} The next appropriate response for the request this RandomOrgCache
|
44 | * represents or, if stack is empty throws an error.
|
45 | * @throws RandomOrgCacheEmptyError if the cache is empty.
|
46 | */
|
47 | get(): any[];
|
48 | /**
|
49 | * Get next response or wait until the next value is available. This method
|
50 | * will block until a value is available. Note: this method will throw an error
|
51 | * if the cache is empty and has been paused, i.e. is not being populated. If
|
52 | * the cache was constructed with unsuitable parameter values or the daily allowance
|
53 | * of bits/requests has been reached, the appropriate error will also be thrown.
|
54 | * @returns {Promise<any[]>} The next appropriate response for the request this
|
55 | * RandomOrgCache represents.
|
56 | * @throws RandomOrgCacheEmptyError if the cache is empty and is paused.
|
57 | */
|
58 | getOrWait(): Promise<any[]>;
|
59 | /**
|
60 | * Gets the number of result sets remaining in the cache.
|
61 | *
|
62 | * This essentially returns how often get() may be called without
|
63 | * a cache refill.
|
64 | * @returns {number} Current number of cached results.
|
65 | */
|
66 | getCachedValues(): number;
|
67 | /**
|
68 | * Gets the number of bits used by this cache.
|
69 | * @returns {number} Number of bits used.
|
70 | */
|
71 | getBitsUsed(): number;
|
72 | /**
|
73 | * Gets number of requests used by this cache.
|
74 | * @returns {number} Number of requests used.
|
75 | */
|
76 | getRequestsUsed(): number;
|
77 | #private;
|
78 | }
|