2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 02:48:55 +00:00

Merge pull request #3878 from MichaelEischer/cheaper-cache-load

cache: Just try to open cache entry without calling stat first
This commit is contained in:
MichaelEischer 2022-08-26 20:33:36 +02:00 committed by GitHub
commit f7808245aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 13 deletions

View File

@ -160,19 +160,17 @@ func (b *Backend) Load(ctx context.Context, h restic.Handle, length int, offset
debug.Log("downloading %v finished", h)
}
if b.Cache.Has(h) {
debug.Log("Load(%v, %v, %v) from cache", h, length, offset)
rd, err := b.Cache.load(h, length, offset)
if err == nil {
err = consumer(rd)
if err != nil {
_ = rd.Close() // ignore secondary errors
return err
}
return rd.Close()
// try loading from cache without checking that the handle is actually cached
rd, err := b.Cache.load(h, length, offset)
if err == nil {
err = consumer(rd)
if err != nil {
_ = rd.Close() // ignore secondary errors
return err
}
debug.Log("error loading %v from cache: %v", h, err)
return rd.Close()
}
debug.Log("error loading %v from cache: %v", h, err)
// if we don't automatically cache this file type, fall back to the backend
if !autoCacheTypes(h) {
@ -181,7 +179,7 @@ func (b *Backend) Load(ctx context.Context, h restic.Handle, length int, offset
}
debug.Log("auto-store %v in the cache", h)
err := b.cacheFile(ctx, h)
err = b.cacheFile(ctx, h)
if err == nil {
return b.loadFromCacheOrDelegate(ctx, h, length, offset, consumer)
}

View File

@ -43,7 +43,7 @@ type readCloser struct {
// given handle. rd must be closed after use. If an error is returned, the
// ReadCloser is nil.
func (c *Cache) load(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
debug.Log("Load from cache: %v", h)
debug.Log("Load(%v, %v, %v) from cache", h, length, offset)
if !c.canBeCached(h.Type) {
return nil, errors.New("cannot be cached")
}