]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/cache/cache.ts
Merge branch 'release/3.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / middlewares / cache / cache.ts
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 }