Documentation ¶
Index ¶
- Variables
- type Cache
- type CacheOptions
- type Frontend
- type FrontendOptions
- type Getter
- type Key
- type RecordWriter
- func (rw *RecordWriter) Bind(f *Frontend, k Key) (Streamer, error)
- func (rw *RecordWriter) BindJSON(f *Frontend, k Key, dst interface{}) (err error)
- func (rw *RecordWriter) Include(f *Frontend, k Key) (err error)
- func (rw *RecordWriter) ReadFrom(r io.Reader) (n int64, err error)
- func (rw *RecordWriter) Write(p []byte) (n int, err error)
- type Streamer
Constants ¶
This section is empty.
Variables ¶
var ( // Indicates no components have been written and no error has been returned // in a call to Getter. This is not allowed. ErrEmptyRecord = errors.New("empty record created") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Unified storage for cached records with specific eviction parameters
func NewCache ¶
func NewCache(opts CacheOptions) (c *Cache)
Create new cache with specified memory and LRU eviction limits. After either of these are exceeded, the least recently used cache records will be evicted, until the requirements are satisfied again. Note that this eviction is eventual and not immediate for optimisation purposes.
Pass in zero values to ignore either or both eviction limits.
func (*Cache) NewFrontend ¶
func (c *Cache) NewFrontend(opts FrontendOptions) *Frontend
Create new Frontend for accessing the cache. A Frontend must only be created using this method.
type CacheOptions ¶
type CacheOptions struct { // Maximum amount of memory the cache can consume without forcing eviction MemoryLimit uint // Maximum last use time of record without forcing eviction LRULimit time.Duration }
Options for new cache creation
type Frontend ¶
type Frontend struct {
// contains filtered or unexported fields
}
A frontend for accessing the cache contents
func (*Frontend) EvictByFunc ¶
Evict keys from frontend using matcher function fn. fn returns true, if a key must be evicted.
type FrontendOptions ¶
type FrontendOptions struct { // Will be used for generating fresh cache records for the given key by // the cache engine. These records will be stored by the cache engine and // must not be modified after Get() returns. Get() must be thread-safe. Get Getter // Level level to use for storing records. // Defaults to gzip.DefaultCompression. Level *int }
Options for creating a new cache frontend
type Getter ¶
type Getter func(Key, *RecordWriter) error
Generates fresh cache records for the given key by writing to RecordWriter. Getter must be thread-safe.
type Key ¶
type Key interface{}
Value used to store entries in the cache. Must be a type suitable for being a key in a Go map.
type RecordWriter ¶
type RecordWriter struct {
// contains filtered or unexported fields
}
Provides utility methods for building record buffers and recursive record trees
func (*RecordWriter) Bind ¶
func (rw *RecordWriter) Bind(f *Frontend, k Key) (Streamer, error)
Bind to record from passed frontend by key and return a consumable stream of the retrieved record. The record generated by rw will automatically be evicted from its parent cache on eviction of the included record.
func (*RecordWriter) BindJSON ¶
func (rw *RecordWriter) BindJSON( f *Frontend, k Key, dst interface{}, ) (err error)
Bind to record from passed frontend by key and decode it as JSON into dst. The record generated by rw will automatically be evicted from its parent cache on eviction of the included record.
func (*RecordWriter) Include ¶
func (rw *RecordWriter) Include(f *Frontend, k Key) (err error)
Include data from passed frontend by key and bind it to rw. The record generated by rw will automatically be evicted from its parent cache on eviction of the included record.
type Streamer ¶
type Streamer interface { // Can be called safely from multiple goroutines io.WriterTo // Create a new io.Reader for this stream. // Multiple instances of such an io.Reader can exist and be read // concurrently. NewReader() io.Reader // Convenience method for efficiently decoding stream contents as JSON into // the destination variable. // // dst: pointer to destination variable DecodeJSON(dst interface{}) error // Create a new io.ReadCloser for the unzipped content of this stream. // // It is the caller's responsibility to call Close on the io.ReadCloser // when finished reading. Unzip() io.ReadCloser // Return SHA1 hash of the content SHA1() [sha1.Size]byte // Return strong etag of content ETag() string }
Readable stream with support for io.WriterTo and conversion to io.Reader interfaces