This commit is contained in:
6543 2022-09-19 12:15:14 +02:00
parent 94cb43508c
commit af49f9a8f6
No known key found for this signature in database
GPG key ID: C99B82E40B027BAE
2 changed files with 8 additions and 7 deletions

View file

@ -65,7 +65,7 @@ type BranchTimestamp struct {
}
type writeCacheReader struct {
r io.Reader
rc io.ReadCloser
buff *bytes.Buffer
f *FileResponse
cacheKey string
@ -74,7 +74,7 @@ type writeCacheReader struct {
}
func (t *writeCacheReader) Read(p []byte) (n int, err error) {
n, err = t.r.Read(p)
n, err = t.rc.Read(p)
if err != nil {
t.hasErr = true
} else if n > 0 {
@ -85,16 +85,17 @@ func (t *writeCacheReader) Read(p []byte) (n int, err error) {
func (t *writeCacheReader) Close() error {
if !t.hasErr {
t.f.Body = t.buff.Bytes()
t.cache.Set(t.cacheKey, *t.f, fileCacheTimeout)
fc := *t.f
fc.Body = t.buff.Bytes()
_ = t.cache.Set(t.cacheKey, fc, fileCacheTimeout)
}
return t.Close()
return t.rc.Close()
}
func (f FileResponse) CreateCacheReader(r io.ReadCloser, cache cache.SetGetKey, cacheKey string) io.ReadCloser {
buf := []byte{}
return &writeCacheReader{
r: r,
rc: r,
buff: bytes.NewBuffer(buf),
f: &f,
cacheKey: cacheKey,

View file

@ -97,7 +97,7 @@ func (client *Client) ServeRawContent(targetOwner, targetRepo, ref, resource str
log := log.With().Str("cache_key", cacheKey).Logger()
// handle if cache entry exist
if cache, ok := client.responseCache.Get(cacheKey); ok == true {
if cache, ok := client.responseCache.Get(cacheKey); ok {
cache := cache.(FileResponse)
// TODO: check against some timestamp missmatch?!?
if cache.Exists {