1 | 'use strict';
|
2 |
|
3 | const createArgErrorMessageProd = require('../private/createArgErrorMessageProd');
|
4 | const Cache = require('./Cache');
|
5 | const cacheEntryPrune = require('./cacheEntryPrune');
|
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 | module.exports = function cachePrune(cache, cacheKeyMatcher) {
|
33 | if (!(cache instanceof Cache))
|
34 | throw new TypeError(
|
35 | typeof process === 'object' && process.env.NODE_ENV !== 'production'
|
36 | ? 'Argument 1 `cache` must be a `Cache` instance.'
|
37 | : createArgErrorMessageProd(1)
|
38 | );
|
39 |
|
40 | if (cacheKeyMatcher !== undefined && typeof cacheKeyMatcher !== 'function')
|
41 | throw new TypeError(
|
42 | typeof process === 'object' && process.env.NODE_ENV !== 'production'
|
43 | ? 'Argument 2 `cacheKeyMatcher` must be a function.'
|
44 | : createArgErrorMessageProd(2)
|
45 | );
|
46 |
|
47 | for (const cacheKey in cache.store)
|
48 | if (!cacheKeyMatcher || cacheKeyMatcher(cacheKey))
|
49 | cacheEntryPrune(cache, cacheKey);
|
50 | };
|