UNPKG

2.98 kBTypeScriptView Raw
1/** @module cache */
2import { IReconfigurable } from 'pip-services3-commons-node';
3import { ConfigParams } from 'pip-services3-commons-node';
4import { ICache } from './ICache';
5/**
6 * Cache that stores values in the process memory.
7 *
8 * Remember: This implementation is not suitable for synchronization of distributed processes.
9 *
10 * ### Configuration parameters ###
11 *
12 * __options:__
13 * - timeout: default caching timeout in milliseconds (default: 1 minute)
14 * - max_size: maximum number of values stored in this cache (default: 1000)
15 *
16 * @see [[ICache]]
17 *
18 * ### Example ###
19 *
20 * let cache = new MemoryCache();
21 *
22 * cache.store("123", "key1", "ABC", (err) => {
23 * cache.store("123", "key1", (err, value) => {
24 * // Result: "ABC"
25 * });
26 * });
27 *
28 */
29export declare class MemoryCache implements ICache, IReconfigurable {
30 private _cache;
31 private _count;
32 private _timeout;
33 private _maxSize;
34 /**
35 * Creates a new instance of the cache.
36 */
37 constructor();
38 /**
39 * Configures component by passing configuration parameters.
40 *
41 * @param config configuration parameters to be set.
42 */
43 configure(config: ConfigParams): void;
44 /**
45 * Clears component state.
46 *
47 * @param correlationId (optional) transaction id to trace execution through call chain.
48 * @param callback callback function that receives error or null no errors occured.
49 */
50 private cleanup;
51 /**
52 * Retrieves cached value from the cache using its key.
53 * If value is missing in the cache or expired it returns null.
54 *
55 * @param correlationId (optional) transaction id to trace execution through call chain.
56 * @param key a unique value key.
57 * @param callback callback function that receives cached value or error.
58 */
59 retrieve(correlationId: string, key: string, callback: (err: any, value: any) => void): void;
60 /**
61 * Stores value in the cache with expiration time.
62 *
63 * @param correlationId (optional) transaction id to trace execution through call chain.
64 * @param key a unique value key.
65 * @param value a value to store.
66 * @param timeout expiration timeout in milliseconds.
67 * @param callback (optional) callback function that receives an error or null for success
68 */
69 store(correlationId: string, key: string, value: any, timeout: number, callback: (err: any, value: any) => void): void;
70 /**
71 * Removes a value from the cache by its key.
72 *
73 * @param correlationId (optional) transaction id to trace execution through call chain.
74 * @param key a unique value key.
75 * @param callback (optional) callback function that receives an error or null for success
76 */
77 remove(correlationId: string, key: string, callback: (err: any) => void): void;
78}