@@ -72,15 +72,12 @@ const middleWare = (module.exports = function(options) {
72
72
res . locals . cacheKey || res . locals . fetchUrl
73
73
) ;
74
74
75
+ const startTime = process . hrtime ( ) ;
76
+
75
77
try {
76
78
if ( fs . existsSync ( assetCachePath ) ) {
77
79
const firstFile = fs . readdirSync ( assetCachePath ) [ 0 ] ;
78
80
79
- if ( options . logger )
80
- options . logger . debug (
81
- `Reading buffer from path ${ assetCachePath } /${ firstFile } `
82
- ) ;
83
-
84
81
const [ contentType , contentLength ] = middleWare . decodeAssetCacheName (
85
82
firstFile
86
83
) ;
@@ -89,6 +86,14 @@ const middleWare = (module.exports = function(options) {
89
86
res . locals . contentType = contentType ;
90
87
91
88
res . locals . buffer = fs . readFileSync ( `${ assetCachePath } /${ firstFile } ` ) ;
89
+
90
+ const [ seconds , nanoSeconds ] = process . hrtime ( startTime ) ;
91
+ if ( options . logger )
92
+ options . logger . info (
93
+ `Read buffer from path ${ assetCachePath } /${ firstFile } in ${ seconds *
94
+ 1000 +
95
+ nanoSeconds / 1e6 } ms`
96
+ ) ;
92
97
} else {
93
98
// node 10 supports recursive: true, but who knows?
94
99
middleWare . makeDirIfNotExists ( options . cacheDir ) ;
@@ -101,17 +106,21 @@ const middleWare = (module.exports = function(options) {
101
106
const blob = await ( await fetch ( res . locals . fetchUrl ) ) . blob ( ) ;
102
107
103
108
const fileName = middleWare . encodeAssetCacheName ( blob . type , blob . size ) ;
104
- if ( options . logger )
105
- options . logger . debug (
106
- `Writing buffer to path ${ assetCachePath } /${ fileName } `
107
- ) ;
108
109
109
110
res . locals . buffer = Buffer . from ( await blob . arrayBuffer ( ) , "binary" ) ;
110
111
111
112
res . locals . contentType = blob . type ;
112
113
res . locals . contentLength = blob . size ;
113
114
114
115
fs . writeFileSync ( `${ assetCachePath } /${ fileName } ` , res . locals . buffer ) ;
116
+
117
+ const [ seconds , nanoSeconds ] = process . hrtime ( startTime ) ;
118
+ if ( options . logger )
119
+ options . logger . info (
120
+ `Wrote buffer to path ${ assetCachePath } /${ fileName } in ${ seconds *
121
+ 1000 +
122
+ nanoSeconds / 1e6 } ms`
123
+ ) ;
115
124
}
116
125
117
126
next ( ) ;
0 commit comments