Documentation
¶
Index ¶
Constants ¶
const ( DirObjects = "objects" DirTemp = "tmp" )
Subdirectories for storing objects.
Variables ¶
var ErrKeyNotFound = errors.New("key not found")
ErrKeyNotFound is returned when a cache key cannot be found.
Functions ¶
func DefaultFilenamer ¶
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.
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 ¶
func (fc *FilesystemCache) Get(key string) (ReadAtReadCloser, io.WriteCloser, Source, error)
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.