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 ¶
var ErrInvalidRecord = errors.New("record must be non nil and comparable (implement lesser interface)")
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 utility 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 ¶
Close closes all opened writers; will continue on error and return all (if any) errors
func (*Cache) ClosePath ¶
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 ¶
FreeWriterbuffers checks how many more writers can be opened within the current limit
func (*Cache) GetWriter ¶
func (mfw *Cache) GetWriter(path string) (io.WriteCloser, error)
GetWriter returns a synced write closer. The method is a WriterFactory
func (*Cache) RequiresNewWriter ¶
RequiresNewWriter checks if the record will fit withing an existing partition