proxy.golang.org : github.com/neilotoole/streamcache
Package streamcache implements an in-memory cache mechanism that allows multiple callers to read some or all of the contents of a source reader, while only reading from the source reader once; when there's only one final reader remaining, the cache is discarded and the final reader reads directly from the source. Let's say we're reading from stdin. For example: In this scenario, myprogram wants to detect the type of data in the file/pipe, and then print it out. That sampling could be done in a separate goroutine per sampler type. The input file could be, let's say, a CSV file, or a JSON file. The obvious approach is to inspect the first few lines of the input, and check if the input is either valid CSV, or valid JSON. After that process, let's say we want to dump out the entire contents of the input. Package streamcache provides a facility to create a caching Stream from an underlying io.Reader (os.Stdin in this scenario), and spawn multiple readers, each of which can operate independently, in their own goroutines if desired. The underlying source (again, os.Stdin in this scenario) will only be read from once, but its data is available to multiple readers, because that data is cached in memory. That is, until after Stream.Seal is invoked: when there's only one final reader left, the cache is discarded, and the final reader reads directly from the underlying source. The entrypoint to this package is streamcache.New, which returns a new Stream instance, from which readers can be created via Stream.NewReader.
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/neilotoole/streamcache
Keywords:
cache
, go
, golang
, io
, multireader
, reader
, stream
License: MIT
Latest release: about 1 year ago
First release: about 4 years ago
Namespace: github.com/neilotoole
Dependent packages: 1
Stars: 20 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 13 days ago