diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-22 11:15:17 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-22 11:48:24 +0200 |
commit | 20bafcb61bee2a9a10a500908850c9a7d5e3c8c5 (patch) | |
tree | 18d0e8eb693b0fce88b21b282ea6f28836763fe6 /server/middlewares/cache/cache.ts | |
parent | 13e13377918b65c30b9334920fef4b43e70b964e (diff) | |
download | PeerTube-20bafcb61bee2a9a10a500908850c9a7d5e3c8c5.tar.gz PeerTube-20bafcb61bee2a9a10a500908850c9a7d5e3c8c5.tar.zst PeerTube-20bafcb61bee2a9a10a500908850c9a7d5e3c8c5.zip |
Move apicache in peertube
Allow us to upgrade to node 16
Diffstat (limited to 'server/middlewares/cache/cache.ts')
-rw-r--r-- | server/middlewares/cache/cache.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/server/middlewares/cache/cache.ts b/server/middlewares/cache/cache.ts new file mode 100644 index 000000000..48162a0ae --- /dev/null +++ b/server/middlewares/cache/cache.ts | |||
@@ -0,0 +1,32 @@ | |||
1 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' | ||
2 | import { Redis } from '../../lib/redis' | ||
3 | import { ApiCache, APICacheOptions } from './shared' | ||
4 | |||
5 | // Ensure Redis is initialized | ||
6 | Redis.Instance.init() | ||
7 | |||
8 | const defaultOptions: APICacheOptions = { | ||
9 | excludeStatus: [ | ||
10 | HttpStatusCode.FORBIDDEN_403, | ||
11 | HttpStatusCode.NOT_FOUND_404 | ||
12 | ] | ||
13 | } | ||
14 | |||
15 | function cacheRoute (duration: string) { | ||
16 | const instance = new ApiCache(defaultOptions) | ||
17 | |||
18 | return instance.buildMiddleware(duration) | ||
19 | } | ||
20 | |||
21 | function cacheRouteFactory (options: APICacheOptions) { | ||
22 | const instance = new ApiCache({ ...defaultOptions, ...options }) | ||
23 | |||
24 | return instance.buildMiddleware.bind(instance) | ||
25 | } | ||
26 | |||
27 | // --------------------------------------------------------------------------- | ||
28 | |||
29 | export { | ||
30 | cacheRoute, | ||
31 | cacheRouteFactory | ||
32 | } | ||