cache.ts 513 Bytes
Newer Older
Chocobozzz's avatar
Chocobozzz committed
1
import { Redis } from '../lib/redis'
2
import * as apicache from 'apicache'
Chocobozzz's avatar
Chocobozzz committed
3

4
5
// Ensure Redis is initialized
Redis.Instance.init()
6

7
const defaultOptions = {
8
  redisClient: Redis.Instance.getClient(),
9
10
11
12
  appendKey: () => Redis.Instance.getPrefix(),
  statusCodes: {
    exclude: [ 404, 403 ]
  }
Chocobozzz's avatar
Chocobozzz committed
13
14
}

15
16
17
18
const cacheRoute = (extraOptions = {}) => apicache.options({
  ...defaultOptions,
  ...extraOptions
}).middleware
19

Chocobozzz's avatar
Chocobozzz committed
20
21
22
// ---------------------------------------------------------------------------

export {
Chocobozzz's avatar
Chocobozzz committed
23
  cacheRoute
Chocobozzz's avatar
Chocobozzz committed
24
}