UNPKG

1.52 kBTypeScriptView Raw
1/**
2 * Simple in memory cache provider. To be used to store state of requests that needs
3 * to be validated/checked when a response is received.
4 *
5 * This is the default implementation of a cache provider used by Passport-SAML. For
6 * multiple server instances/load balanced scenarios (I.e. the SAML request could have
7 * been generated from a different server/process handling the SAML response) this
8 * implementation will NOT be sufficient.
9 *
10 * The caller should provide their own implementation for a cache provider as defined
11 * in the config options for Passport-SAML.
12 * @param options
13 * @constructor
14 */
15export interface CacheItem {
16 value: string;
17 createdAt: number;
18}
19interface CacheProviderOptions {
20 keyExpirationPeriodMs: number;
21}
22export declare class CacheProvider {
23 cacheKeys: Record<string, CacheItem>;
24 options: CacheProviderOptions;
25 constructor(options: Partial<CacheProviderOptions>);
26 /**
27 * Store an item in the cache, using the specified key and value.
28 * Internally will keep track of the time the item was added to the cache
29 * @param id
30 * @param value
31 */
32 saveAsync(key: string, value: string): Promise<CacheItem | null>;
33 /**
34 * Returns the value of the specified key in the cache
35 * @param id
36 * @returns {boolean}
37 */
38 getAsync(key: string): Promise<string | null>;
39 /**
40 * Removes an item from the cache if it exists
41 * @param key
42 */
43 removeAsync(key: string): Promise<string | null>;
44}
45export {};