cache

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirObjects = "objects"
	DirTemp    = "tmp"
)

Subdirectories for storing objects.

Variables

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

ErrKeyNotFound is returned when a cache key cannot be found.

Functions

func DefaultFilenamer

func DefaultFilenamer(key string) string

DefaultFilenamer is the default filenamer used when naming a cached file on disk.

Types

type ConcurrentReadWriter

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

ConcurrentReadWriter wraps a ReadAtWriteCloser (such as os.File) and allows multiple readers to stream data as it is being written.

func NewConcurrentReadWriter

func NewConcurrentReadWriter(r ReadAtWriteCloser) *ConcurrentReadWriter

NewConcurrentReadWriter returns a new ConcurrentReadWriter.

func (*ConcurrentReadWriter) Close

func (crw *ConcurrentReadWriter) Close() error

Close closes the underlying read/writer, but blocks until all readers have been closed.

func (*ConcurrentReadWriter) Closed

func (crw *ConcurrentReadWriter) Closed() bool

Closed returns whether or not the ConcurrentReadWriter has been closed.

func (*ConcurrentReadWriter) Reader

func (crw *ConcurrentReadWriter) Reader() ReadAtReadCloser

Reader returns an io.Reader that can be used to read data as it is being written. The Read() method will return EOF only when all data has been read and Close() has been called, otherwise it will block.

Nil will be returned if the ConcurrentReadWriter has been closed.

func (*ConcurrentReadWriter) Write

func (crw *ConcurrentReadWriter) Write(p []byte) (n int, err error)

Write implements the standard Write interface.

type FilesystemCache

type FilesystemCache struct {
	Filenamer func(key string) string
	// contains filtered or unexported fields
}

FilesystemCache caches files to disk.

func NewFilesystemCache

func NewFilesystemCache(directory string) (*FilesystemCache, error)

NewFilesystemCache returns a new FilesystemCache.

func (*FilesystemCache) Directory

func (fc *FilesystemCache) Directory() string

Directory returns the cache directory.

func (*FilesystemCache) Done

func (fc *FilesystemCache) Done(key string, err error) error

Done indicates that we're done with a certain cache key.

If an error is passed, the cache is deleted, otherwise the cache file is moved to the cache directory.

func (*FilesystemCache) Get

Get returns: - A reader so that data can be read from the cache. - A writer if the cache doesn't yet exist so that it can be populated. - The source of the cache (disk, inflight, or fresh)

A reader can be read from whilst the writer is being written to. The readers will only EOF if the writer or reader is closed.

A writer can only be closed if all readers have been closed.

type ReadAtReadCloser

type ReadAtReadCloser interface {
	io.ReaderAt
	io.ReadCloser
}

ReadAtReadCloser is the interface that groups the basic ReadAt, Read and Close methods.

type ReadAtWriteCloser

type ReadAtWriteCloser interface {
	io.ReaderAt
	io.WriteCloser
}

ReadAtWriteCloser is the interface that groups the basic ReadAt, Write and Close methods.

type Source

type Source string

Source indicates the source of the cached content.

const (
	SourceDisk     Source = "disk"
	SourceInflight Source = "inflight"
	SourceFresh    Source = "fresh"
)

Sources that indicate where a cache is being served from: - SourceDisk (local disk cache) - SourceInflight (inflight cache) - SourceFresh (non-cached, fresh data)

Jump to

Keyboard shortcuts

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