This commit is contained in:
6543 2022-09-18 22:41:52 +02:00
parent 4a2a14272b
commit 94cb43508c
No known key found for this signature in database
GPG key ID: B8BE6D610E61C862
2 changed files with 57 additions and 30 deletions

View file

@ -158,26 +158,12 @@ func (client *Client) ServeRawContent(targetOwner, targetRepo, ref, resource str
}
// now we write to cache and respond at the sime time
// TODO: at the sime time !!!
/*
we create a new type that implement an writer witch write to cache based on key etc ...
// TODO: cache is half-empty if request is cancelled - does the ctx.Err() below do the trick?
// err = res.BodyWriteTo(io.MultiWriter(ctx.Response().BodyWriter(), &cacheBodyWriter))
*/
body, err := io.ReadAll(io.LimitReader(reader, fileCacheSizeLimit))
if err != nil {
log.Error().Err(err).Msg("not expected")
}
if err := client.responseCache.Set(cacheKey, FileResponse{
fileResp := FileResponse{
Exists: true,
ETag: resp.Header.Get(eTagHeader),
MimeType: mimeType,
Body: body,
}, fileCacheTimeout); err != nil {
log.Error().Err(err).Msg("could not save content in cache")
}
return io.NopCloser(bytes.NewReader(body)), resp.Response, nil
return fileResp.CreateCacheReader(reader, client.responseCache, cacheKey), resp.Response, nil
}
case http.StatusNotFound: