cache

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2017 License: BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	restic.Backend
	*Cache
	// contains filtered or unexported fields
}

Backend wraps a restic.Backend and adds a cache.

func (*Backend) IsNotExist

func (b *Backend) IsNotExist(err error) bool

IsNotExist returns true if the error is caused by a non-existing file.

func (*Backend) Load

func (b *Backend) Load(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error)

Load loads a file from the cache or the backend.

func (*Backend) Remove

func (b *Backend) Remove(ctx context.Context, h restic.Handle) error

Remove deletes a file from the backend and the cache if it has been cached.

func (*Backend) Save

func (b *Backend) Save(ctx context.Context, h restic.Handle, rd io.Reader) (err error)

Save stores a new file in the backend and the cache.

func (*Backend) Stat

func (b *Backend) Stat(ctx context.Context, h restic.Handle) (restic.FileInfo, error)

Stat tests whether the backend has a file. If it does not exist but still exists in the cache, it is removed from the cache.

type Cache

type Cache struct {
	Path             string
	Base             string
	PerformReadahead func(restic.Handle) bool
}

Cache manages a local cache.

func New

func New(id string, basedir string) (c *Cache, err error)

New returns a new cache for the repo ID at basedir. If basedir is the empty string, the default cache location (according to the XDG standard) is used.

For partial files, the complete file is loaded and stored in the cache when performReadahead returns true.

func TestNewCache

func TestNewCache(t testing.TB) (*Cache, func())

TestNewCache returns a cache in a temporary directory which is removed when cleanup is called.

func (*Cache) BaseDir

func (c *Cache) BaseDir() string

BaseDir returns the base directory.

func (*Cache) Clear

func (c *Cache) Clear(t restic.FileType, valid restic.IDSet) error

Clear removes all files of type t from the cache that are not contained in the set valid.

func (*Cache) Has

func (c *Cache) Has(h restic.Handle) bool

Has returns true if the file is cached.

func (*Cache) IsNotExist

func (c *Cache) IsNotExist(err error) bool

IsNotExist returns true if the error was caused by a non-existing file.

func (*Cache) Load

func (c *Cache) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, error)

Load returns a reader that yields the contents of the file with the given handle. rd must be closed after use. If an error is returned, the ReadCloser is nil.

func (*Cache) Remove

func (c *Cache) Remove(h restic.Handle) error

Remove deletes a file. When the file is not cache, no error is returned.

func (*Cache) Save

func (c *Cache) Save(h restic.Handle, rd io.Reader) error

Save saves a file in the cache.

func (*Cache) SaveWriter

func (c *Cache) SaveWriter(h restic.Handle) (io.WriteCloser, error)

SaveWriter returns a writer for the cache object h. It must be closed after writing is finished.

func (*Cache) Wrap

func (c *Cache) Wrap(be restic.Backend) restic.Backend

Wrap returns a backend with a cache.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL