File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ const STATUS_500 = {
1010}
1111
1212module . exports = ( config = { } ) => {
13+ const cache = new Map ( )
14+
1315 if ( ! config . defaultRoute ) {
1416 config . defaultRoute = ( ) => {
1517 return new Response ( null , STATUS_404 )
@@ -45,8 +47,16 @@ module.exports = (config = {}) => {
4547 req . path = path || '/'
4648 req . query = queryIndex > 0 ? qs . parse ( url . substring ( queryIndex + 1 ) ) : { }
4749
48- const match = router . find ( req . method , req . path )
49- if ( match . handlers . length > 0 ) {
50+ const cacheKey = `${ req . method } :${ req . path } `
51+ let match = null
52+ if ( cache . has ( cacheKey ) ) {
53+ match = cache . get ( cacheKey )
54+ } else {
55+ match = router . find ( req . method , req . path )
56+ cache . set ( cacheKey , match )
57+ }
58+
59+ if ( match ?. handlers ?. length > 0 ) {
5060 if ( ! req . params ) {
5161 req . params = { }
5262 }
You can’t perform that action at this time.
0 commit comments