aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/cache.ts
blob: cb24d9e0e51698eb317b1c8cdfb9d9c7da38b700 (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
import { Redis } from '../lib/redis'
import * as apicache from 'apicache'

// Ensure Redis is initialized
Redis.Instance.init()

const defaultOptions = {
  redisClient: Redis.Instance.getClient(),
  appendKey: () => Redis.Instance.getPrefix(),
  statusCodes: {
    exclude: [ 404, 403 ]
  }
}

const cacheRoute = (extraOptions = {}) => apicache.options({
  ...defaultOptions,
  ...extraOptions
}).middleware

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

export {
  cacheRoute
}