@@ -144,8 +144,9 @@ func (c *Cacher) Get(ctx context.Context, name string) (_ io.ReadCloser, oerr er
144
144
}
145
145
146
146
// Check whether the file already exists locally.
147
- if rc , err := openReader (path ); err == nil {
147
+ if rc , size , err := openReader (path ); err == nil {
148
148
c .getLocalHit .Add (1 )
149
+ c .getLocalBytes .Add (size )
149
150
return rc , nil
150
151
} else if errors .Is (err , os .ErrNotExist ) {
151
152
c .getLocalMiss .Add (1 )
@@ -178,7 +179,8 @@ func (c *Cacher) Get(ctx context.Context, name string) (_ io.ReadCloser, oerr er
178
179
if _ , err := c .putLocal (ctx , name , path , obj .Body ); err != nil {
179
180
return nil , err
180
181
}
181
- return openReader (path )
182
+ rc , _ , err := openReader (path )
183
+ return rc , err
182
184
}
183
185
184
186
// putLocal reports whether the specified path already exists in the local
@@ -311,12 +313,12 @@ func (c *Cacher) vlogf(msg string, args ...any) {
311
313
}
312
314
}
313
315
314
- func openReader (path string ) (io.ReadCloser , error ) {
316
+ func openReader (path string ) (_ io.ReadCloser , size int64 , _ error ) {
315
317
data , err := os .ReadFile (path )
316
318
if err != nil {
317
- return nil , err
319
+ return nil , 0 , err
318
320
}
319
- return io .NopCloser (bytes .NewReader (data )), nil
321
+ return io .NopCloser (bytes .NewReader (data )), int64 ( len ( data )), nil
320
322
}
321
323
322
324
func openFileSize (path string ) (io.ReadCloser , int64 , error ) {
0 commit comments