2
1

cache.ts 705 B

12345678910111213141516171819202122232425262728
  1. import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
  2. import { ApiCache, APICacheOptions } from './shared'
  3. const defaultOptions: APICacheOptions = {
  4. excludeStatus: [
  5. HttpStatusCode.FORBIDDEN_403,
  6. HttpStatusCode.NOT_FOUND_404
  7. ]
  8. }
  9. function cacheRoute (duration: string) {
  10. const instance = new ApiCache(defaultOptions)
  11. return instance.buildMiddleware(duration)
  12. }
  13. function cacheRouteFactory (options: APICacheOptions) {
  14. const instance = new ApiCache({ ...defaultOptions, ...options })
  15. return instance.buildMiddleware.bind(instance)
  16. }
  17. // ---------------------------------------------------------------------------
  18. export {
  19. cacheRoute,
  20. cacheRouteFactory
  21. }