aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/middlewares/cache/cache.ts
blob: e14160ba8ed697225e95a9f02da99334d5510e94 (plain) (tree)
1
2
3
                                                                             

                                                    
























                                                                              
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.buildMiddleware.bind(instance)
}

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

export {
  cacheRoute,
  cacheRouteFactory
}