cache

package
v0.0.0-...-c426cd6 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: Apache-2.0 Imports: 5 Imported by: 3

Documentation

Overview

Package cache is an interface to multiple storage backends for Shade. It centralizes the implementation of reading and writing to multiple drive.Clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(c drive.Config) (drive.Client, error)

NewClient returns a Drive client which centralizes reading and writing to multiple Providers.

Types

type ChunkLister

type ChunkLister struct {
	// contains filtered or unexported fields
}

ChunkLister allows iterating the chunks in all child clients.

func (*ChunkLister) Err

func (c *ChunkLister) Err() error

Err returns the error encountered, if any.

func (*ChunkLister) Next

func (c *ChunkLister) Next() bool

Next advances the iterator returned by Sha256.

It attempts to see if the current client has another Sha256 to provide. When a client is exhausted it advances to the next client. If an Err is encountered, iteration stops and Err() is propagated back to the caller.

func (*ChunkLister) Sha256

func (c *ChunkLister) Sha256() []byte

Sha256 returns the chunk pointed to by the pointer.

type Drive

type Drive struct {
	// contains filtered or unexported fields
}

Drive implements the drive.Client interface by reading and writing to the slice of drive.Client interfaces it was provided. It can return a config which describes only its name.

If any of its clients are not Local(), it reports itself as not Local() by returning false. If any of its clients are Persistent(), it requires writes to at least one of those backends to succeed, and reports itself as Persistent().

func (*Drive) GetChunk

func (s *Drive) GetChunk(sha256sum []byte, f *shade.File) ([]byte, error)

GetChunk retrieves a chunk with a given SHA-256 sum. It will be returned from the first client in the slice of structs that returns the chunk.

func (*Drive) GetConfig

func (s *Drive) GetConfig() drive.Config

GetConfig returns the config used to initialize this client.

func (*Drive) GetFile

func (s *Drive) GetFile(sha256sum []byte) ([]byte, error)

GetFile retrieves a file with a given SHA-256 sum. It will be returned from the first client in the slice of structs that returns the chunk.

func (*Drive) ListFiles

func (s *Drive) ListFiles() ([][]byte, error)

ListFiles retrieves all of the File objects known to all of the provided clients. The return is a list of sha256sums of the file object. The keys may be passed to GetChunk() to retrieve the corresponding shade.File.

func (*Drive) Local

func (s *Drive) Local() bool

Local returns true only if all configured storage backends are local to this machine.

func (*Drive) NewChunkLister

func (s *Drive) NewChunkLister() drive.ChunkLister

NewChunkLister returns an iterator which will return all of the chunks known to all child clients.

func (*Drive) Persistent

func (s *Drive) Persistent() bool

Persistent returns true if at least one configured storage backend is Persistent().

func (*Drive) PutChunk

func (s *Drive) PutChunk(sha256sum []byte, chunk []byte, f *shade.File) error

PutChunk writes a chunk associated with a SHA-256 sum. It will attempt to write to all shade backends configured to Write. If any backends are Persistent, it returns an error if all Persistent backends fail to write.

func (*Drive) PutFile

func (s *Drive) PutFile(sha256sum, f []byte) error

PutFile writes the metadata describing a new file. It will be written to all shade backends configured to Write. If any backends are Persistent, it returns an error if all Persistent backends fail to write. f should be marshalled JSON, and may be encrypted.

func (*Drive) ReleaseChunk

func (s *Drive) ReleaseChunk(sha256sum []byte) error

ReleaseChunk calls ReleaseChunk on each of the provided clients in sequence. No errors are returned from child clients.

func (*Drive) ReleaseFile

func (s *Drive) ReleaseFile(sha256sum []byte) error

ReleaseFile calls ReleaseFile on each of the provided clients in sequence. No errors are returned from child clients.

func (*Drive) Warm

func (s *Drive) Warm(chunks [][]byte, f *shade.File)

Warm is passed along to each client that is not Local().

Jump to

Keyboard shortcuts

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