]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/middlewares/cache/cache.ts
Invalidate cache feed even after server restart
[github/Chocobozzz/PeerTube.git] / server / middlewares / cache / cache.ts
CommitLineData
20bafcb6 1import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
20bafcb6
C
2import { ApiCache, APICacheOptions } from './shared'
3
20bafcb6
C
4const defaultOptions: APICacheOptions = {
5 excludeStatus: [
6 HttpStatusCode.FORBIDDEN_403,
7 HttpStatusCode.NOT_FOUND_404
8 ]
9}
10
11function cacheRoute (duration: string) {
12 const instance = new ApiCache(defaultOptions)
13
14 return instance.buildMiddleware(duration)
15}
16
17function cacheRouteFactory (options: APICacheOptions) {
18 const instance = new ApiCache({ ...defaultOptions, ...options })
19
cb0eda56
AG
20 return { instance, middleware: instance.buildMiddleware.bind(instance) }
21}
22
23// ---------------------------------------------------------------------------
24
25function buildPodcastGroupsCache (options: {
26 channelId: number
27}) {
28 return 'podcast-feed-' + options.channelId
20bafcb6
C
29}
30
31// ---------------------------------------------------------------------------
32
33export {
34 cacheRoute,
cb0eda56
AG
35 cacheRouteFactory,
36
37 buildPodcastGroupsCache
20bafcb6 38}