aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/cache/cache.ts
blob: 6041c76c3ce75e861036de4b5f8a07ef959af5f9 (plain) (blame)
1
2
3
4
5
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
33
34
35
36
37
38
import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
import { ApiCache, APICacheOptions } from './shared'

const defaultOptions: APICacheOptions = {
  excludeStatus: [
    HttpStatusCode.FORBIDDEN_403,
    HttpStatusCode.NOT_FOUND_404
  ]
}

function cacheRoute (duration: string) {
  const instance = new ApiCache(defaultOptions)

  return instance.buildMiddleware(duration)
}

function cacheRouteFactory (options: APICacheOptions) {
  const instance = new ApiCache({ ...defaultOptions, ...options })

  return { instance, middleware: instance.buildMiddleware.bind(instance) }
}

// ---------------------------------------------------------------------------

function buildPodcastGroupsCache (options: {
  channelId: number
}) {
  return 'podcast-feed-' + options.channelId
}

// ---------------------------------------------------------------------------

export {
  cacheRoute,
  cacheRouteFactory,

  buildPodcastGroupsCache
}