aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/middlewares/cache.ts
blob: e508b22a6db045eb04d13c0a468f389998dd0339 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                    
                                                                          
                                    
 

                              
 
                        
                                          

                                              



                                   
   

 



                                                            
 


                                                                              
            
 
import * as apicache from 'apicache'
import { HttpStatusCode } from '../../shared/models/http/http-error-codes'
import { Redis } from '../lib/redis'

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

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

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

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

export {
  cacheRoute
}