stash

package module
v0.0.0-...-5c97203 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2019 License: BSD-3-Clause Imports: 11 Imported by: 0

README

Stash

A Go package for disk-based blob cache.

Installation

Install Stash using the go get command:

$ go get github.com/chikamim/stash

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.

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

func NewDeflateWriter

func NewDeflateWriter(w io.WriteCloser) io.WriteCloser

Types

type Cache

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

func New

func New(dir string, size, cap int64, useDeflate bool) (*Cache, error)

New creates a Cache backed by dir on disk. The cache allows at most "cap" files of total size "size". If "useDeflate" is true, blobs will be compressed by lz4 for reduce disk usage.

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) PutFile

func (c *Cache) PutFile(key, srcpath string) error

PutFile adds the contents of a file path as a blog to the cache. The source file will be moved or deleted.

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.

func (*Cache) Warmup

func (c *Cache) Warmup() error

type DeflateReader

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

func NewDeflateReader

func NewDeflateReader(r io.ReadCloser) *DeflateReader

func (*DeflateReader) Close

func (d *DeflateReader) Close() error

func (*DeflateReader) Read

func (d *DeflateReader) Read(p []byte) (int, error)

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