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 = {
10
10
}
11
11
12
12
module . exports = ( config = { } ) => {
13
+ const cache = new Map ( )
14
+
13
15
if ( ! config . defaultRoute ) {
14
16
config . defaultRoute = ( ) => {
15
17
return new Response ( null , STATUS_404 )
@@ -45,8 +47,16 @@ module.exports = (config = {}) => {
45
47
req . path = path || '/'
46
48
req . query = queryIndex > 0 ? qs . parse ( url . substring ( queryIndex + 1 ) ) : { }
47
49
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 ) {
50
60
if ( ! req . params ) {
51
61
req . params = { }
52
62
}
You can’t perform that action at this time.
0 commit comments