writercache

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package multiwriter provides a utility to write byte-streams to one or more independent writers; each which will be automatically closed after an idle time or by an LRU approach.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidRecord = errors.New("record must be non nil and comparable (implement lesser interface)")
View Source
var ErrTooManyPartitions = errors.New("can not write new record, would create too many partions in the cache")

Functions

This section is empty.

Types

type Cache

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

Cache is a utillity that keeps an index of multiple writers, indexed by a string (most often path) if a writer is requested and doesn't exist it gets created (using the provided factory). Writers that aren't used for long enough are automatically closed. All writers are also closed on the ctx.Done.

func NewCache

func NewCache(ctx context.Context, writerFactory writerfactory.WriterFactory, ttl time.Duration, maxCacheEntires int) *Cache

NewCache will dynamically open writers for writing and close them on inactivity or when maxCacheEntires has been populated into the cache, at which point the oldest item will be closed.

func (*Cache) Close

func (mfw *Cache) Close() error

Close closes all opened writers; will continue on error and return all (if any) errors

func (*Cache) ClosePath

func (mfw *Cache) ClosePath(path string) error

ClosePath closes one specific path; will return nil if the path doesn't exist or is already closed; Otherwise the reuslt of the writer Close function.

func (*Cache) FreeWriterbuffers

func (mfw *Cache) FreeWriterbuffers() int

FreeWriterbuffers checks how many more writers can be opened within the current limit

func (*Cache) GetWriter

func (mfw *Cache) GetWriter(path string) (eioutil.WriteCloser, error)

GetWriter returns a synced write closer. The method is a WriterFactory

func (*Cache) RequiresNewWriter

func (mfw *Cache) RequiresNewWriter(path string) bool

RequiresNewWriter checks if the record will fit withing an existing partition

func (*Cache) Write

func (mfw *Cache) Write(path string, p []byte) (int, error)

Write gets an existing writers for the path or creates one and saves it for later re-use. If the path contains {suffix} it will be replaced by a unique counter + timestamp.

Jump to

Keyboard shortcuts

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