stash

package module
v1.0.0-...-1129c19 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2017 License: BSD-3-Clause Imports: 10 Imported by: 1

README

Stash

A Go package for disk-based blob cache.

Installation

Install Stash using the go get command:

$ go get gopkg.in/stash.v1

The only dependency is the Go distribution.

Motivation

This package allows us to reduce calls to our blob storage by caching the most recently used blobs to disk.

Documentation

Contributing

Contributions are welcome.

License

Stash is available under the BSD (3-Clause) License.

Disclaimer

The package is a work in progress. It is functional, but does not claim to be production-ready. Please use it at your own risk.

The icon, made by Smashicons from www.flaticon.com, is licensed by CC 3.0 BY.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")

	ErrBadDir  = errors.New("invalid directory")
	ErrBadSize = errors.New("storage size must be greater then zero")
	ErrBadCap  = errors.New("file number must be greater then zero")

	ErrTooLarge = errors.New("file size must be less or equal storage size")
)

Functions

This section is empty.

Types

type Cache

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

func New

func New(dir string, sz, c int64) (*Cache, error)

New creates a Cache backed by dir on disk. The cache allows at most c files of total size sz.

func (*Cache) Get

func (c *Cache) Get(key string) (io.ReadCloser, error)

Get returns a reader for a blob in the cache, or ErrNotFound otherwise.

func (*Cache) Keys

func (c *Cache) Keys() []string

Keys returns a list of keys in the cache.

func (*Cache) Put

func (c *Cache) Put(key string, val []byte) error

Put adds a byte slice as a blob to the cache against the given key.

func (*Cache) PutReader

func (c *Cache) PutReader(key string, r io.Reader) error

PutReader adds the contents of a reader as a blob to the cache against the given key.

type FileError

type FileError struct {
	Dir string
	Key string
	Err error
}

FileError records the storage directory name and key of the that failed to cached.

func (*FileError) Error

func (e *FileError) Error() string

type Meta

type Meta struct {
	Key  string
	Size int64
	Path string
}

Jump to

Keyboard shortcuts

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