1 | module.exports = ({
|
2 | router,
|
3 | cache,
|
4 | asyncMiddleware,
|
5 | getConfig,
|
6 | handleResponse,
|
7 | }) => {
|
8 |
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | router.get(
|
24 | '/cache/clear.:ext?',
|
25 | asyncMiddleware(async (req, res) => {
|
26 | const config = await getConfig();
|
27 |
|
28 | if (!config.cache.enabled) {
|
29 | handleResponse(req, res, 'Cache disabled');
|
30 | return;
|
31 | }
|
32 |
|
33 | const items = [];
|
34 |
|
35 | cache.forEach((value, key) => {
|
36 | if (key.indexOf(req.session.slug) === 0) {
|
37 | items.push(key);
|
38 | }
|
39 | });
|
40 |
|
41 | items.forEach(key => cache.del(key));
|
42 |
|
43 | handleResponse(req, res, `${items.length} items removed from cache`);
|
44 | })
|
45 | );
|
46 |
|
47 | };
|