Documentation ¶
Index ¶
- Variables
- func ConfigureDBPath(path string)
- func DequeueAll(q Queue, dest interface{}) error
- func Tar(w io.Writer, fileCaches ...Queue) error
- func Untar(destDir string, r io.Reader) error
- type DropMode
- type EncodingType
- type FileCache
- func (f *FileCache) Close() error
- func (f *FileCache) Decode(data []byte) ([]interface{}, error)
- func (f *FileCache) Dequeue(obj interface{}) error
- func (f *FileCache) Destroy() error
- func (f *FileCache) Encode() ([]byte, error)
- func (f *FileCache) EncodeToReader() (io.Reader, int64, error)
- func (f *FileCache) Enqueue(obj interface{}) error
- func (f *FileCache) Errors() chan error
- func (f *FileCache) Name() string
- func (f *FileCache) Run(ctx context.Context) error
- type Option
- type Queue
Constants ¶
This section is empty.
Variables ¶
var ( // ErrQueueClosed is returned when enqueue/dequeue is being called // after Close/Destroy. ErrQueueClosed = errors.New("queue doesn't exist") // ErrNilType is returned when the encoder is not enabled/invalid. ErrNilType = errors.New("cannot use nil type") // ErrExceedsSize represents the error when the file size exceeds the given size. ErrExceedsSize = errors.New("exceeds max size") )
var ErrTooLarge = errors.New("Data too large")
ErrTooLarge can be returned from `Encode` to indicate that data is large and EncodeToReader should be used
Functions ¶
func DequeueAll ¶
DequeueAll dequeues all elements of type dest from q and stores it into dest.
Types ¶
type EncodingType ¶
type EncodingType int
EncodingType represents the supported encoding types.
const ( Gob EncodingType = iota JSON )
Encoding types.
type FileCache ¶
FileCache implements Queue interface.
func NewFileCache ¶
NewFileCache creates a new filecache handler to handle arbitrary types to be stored in on disk. It uses goque which is backend by go's port of levelDB. It implements Queue interface and has tools to encode/decode using msgpack. This package also runs a cleaner job which every 24Hrs, will remove the existing DB completely and create a new DB instance. name - used as the filename in the db for this type. All methods are thread-safe.
func (*FileCache) Decode ¶
Decode decodes the given data and returns the list as []interface. Caller has to type assert the interface to the respected types.
func (*FileCache) Destroy ¶
Destroy drops the db, removes any leftover files/directories and frees the queue.
func (*FileCache) EncodeToReader ¶
EncodeToReader functions like Encode but returns a reader.
type Option ¶
type Option func(*FileCache)
An Option represents a Filecache option.
func OptionDropMode ¶
OptionDropMode used to set the drop mode when maxElements limit has reached. Default: HeadDrop.
func OptionEncoderConfig ¶
OptionEncoderConfig used to set the type and the buffer size. obj - the object type to use with Encode/Decode. bufferSize - when Encode is called, we will limit the encoded data size with the provided bytes size. [0 - infinite entries] Default: Disabled.
func OptionEncodingType ¶
func OptionEncodingType(e EncodingType) Option
OptionEncodingType used to set encoding type. Supported options are JSON and Gob. Default: Gob.
func OptionMaxElements ¶
OptionMaxElements used to set the max elements. maxElements - the db will be restricted to not exceed this limit and any enqueues after this will call dequeue and enqueues the new entry. It is validated before OptionMaxSize. Default: Infinite.
func OptionMaxSize ¶
OptionMaxSize used to set the max data size on disk. maxSize - the db will be restricted to not exceed this limit and any enqueues after this will be dropped with ErrExceedsSize error. In most cases, you need to use OptionMaxElements over this. Default: Disabled.
type Queue ¶
type Queue interface { Name() string Run(ctx context.Context) error Enqueue(element interface{}) error Dequeue(element interface{}) error Close() error Destroy() error Errors() chan error Encode() ([]byte, error) Decode(data []byte) ([]interface{}, error) EncodeToReader() (io.Reader, int64, error) }
Queue interface has all necessary methods to enqueue, dequeue, encode, decode entries.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package mockfilecache is a generated GoMock package.
|
Package mockfilecache is a generated GoMock package. |