Add cache

This commits adds rudimentary support for a cache directory, enabled by
default. The cache directory is created if it does not exist. The cache
is used if there's anything in it, newly created snapshot and index
files are written to the cache automatically.
This commit is contained in:
Alexander Neumann 2017-06-10 13:10:08 +02:00
parent 5ace41471e
commit 9be24a1c9f
14 changed files with 1020 additions and 3 deletions

20
internal/cache/testing.go vendored Normal file
View file

@ -0,0 +1,20 @@
package cache
import (
"testing"
"github.com/restic/restic/internal/restic"
"github.com/restic/restic/internal/test"
)
// TestNewCache returns a cache in a temporary directory which is removed when
// cleanup is called.
func TestNewCache(t testing.TB) (*Cache, func()) {
dir, cleanup := test.TempDir(t)
t.Logf("created new cache at %v", dir)
cache, err := New(restic.NewRandomID().String(), dir)
if err != nil {
t.Fatal(err)
}
return cache, cleanup
}