cache

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2018 License: BSD-2-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const MaxCacheAge = 30 * 24 * time.Hour

MaxCacheAge is the default age (30 days) after which cache directories are considered old.

Variables

This section is empty.

Functions

func All added in v0.9.0

func All(basedir string) (dirs []os.FileInfo, err error)

All returns a list of cache directories.

func DefaultDir added in v0.8.1

func DefaultDir() (cachedir string, err error)

DefaultDir returns the default cache directory for the current OS.

func IsOld added in v0.9.0

func IsOld(t time.Time, maxAge time.Duration) bool

IsOld returns true if the timestamp is considered old.

func Old added in v0.8.1

func Old(basedir string) ([]os.FileInfo, error)

Old returns a list of cache directories with a modification time of more than 30 days ago.

func OlderThan added in v0.9.0

func OlderThan(basedir string, max time.Duration) ([]os.FileInfo, error)

OlderThan returns the list of cache directories older than max.

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, consumer func(rd io.Reader) error) 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

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