cache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close will call the io.Closer on the private cache. Convenience method to be able to call Close from the main function

Types

type Cache

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

func NewCache

func NewCache(opts *Options) (*Cache, error)

NewCache creates

func (*Cache) Close

func (cache *Cache) Close() error

Close will close the database, and persist to disk.

func (*Cache) CountIssues

func (cache *Cache) CountIssues(p *gitlab.Project, opts *gitlab.IssuesStreamOpts) int

func (*Cache) CountKeys

func (cache *Cache) CountKeys(namespace []byte) int

Counts the number of records for the given prefix.

func (*Cache) Delete

func (cache *Cache) Delete(e *Entry) error

Delete removes the key, and calls each deleteHook with the key. Hooks are not guarenteed to run, as an earlier hook might error before it ran.

func (*Cache) Get

func (cache *Cache) Get(namespace []byte, key int, value interface{}) error

Get will retrieve the data from the database, and unmarshal it into the value passed in as last argument. Make sure that value is a pointer receiver.

func (*Cache) GetIssue

func (cache *Cache) GetIssue(p *gitlab.Project, id int) (*gitlab.Issue, error)

Implements IssueReader interface

func (*Cache) GetIssuesStream

func (cache *Cache) GetIssuesStream(p *gitlab.Project, opts *gitlab.IssuesStreamOpts, issueChan chan *gitlab.Issue) error

Implements IssuesReader interface

func (*Cache) GetIssuesUpdatedAt

func (cache *Cache) GetIssuesUpdatedAt(p *gitlab.Project) *time.Time

func (*Cache) GetStream

func (cache *Cache) GetStream(namespace []byte, valueChan chan []byte) error

Returns a stream of instances of records,

func (*Cache) RegisterHook

func (cache *Cache) RegisterHook(hook Hook)

RegisterHook registers the provided hook that will be called during cache Set and SetStream operations

func (*Cache) Set

func (cache *Cache) Set(e *Entry) error

Set will write the value to the key, scoped to the namespace. Once the write is commited, the hooks will run. Hooks are not guarenteed to run, as an earlier hook might return an error.

func (*Cache) SetIssuesUpdatedAt

func (cache *Cache) SetIssuesUpdatedAt(p *gitlab.Project, u *time.Time) error

func (*Cache) SetStream

func (cache *Cache) SetStream(done chan struct{}, entryChan chan *Entry) error

func (*Cache) UpdateIssue

func (cache *Cache) UpdateIssue(p *gitlab.Project, i *gitlab.Issue) error

Implements IssueWriter interface

func (*Cache) UpdateIssuesStream

func (cache *Cache) UpdateIssuesStream(done chan struct{}, p *gitlab.Project, issueChan chan *gitlab.Issue) error

Implements IssuesWriter interface

type DB

type DB interface {
	// Entry will have their Value field overriden
	Get(Entry) error
	GetStream(chan Entry) error

	Set(Entry) error
	SetStream(chan Entry) error

	// Only the Key value needs to be set to work, although all could be filled
	Delete(Entry) error
	io.Closer
}

type Entry

type Entry struct {
	Namespace []byte
	Key       int
	Value     interface{}
}

type Hook

type Hook interface {
	PostWrite(namespace []byte, key int, value interface{}) error
	PostDelete(namespace []byte, key int) error

	// PostBatchWrite is indented to allow the hook to run in batches, where
	// the control of when the hook runs remains in the control of the hook.
	PostBatchWrite(namespace []byte, key int, value interface{}) error
	// Hooks can depend on BatchFlush being called when the current batch is
	// done.
	BatchFlush() error

	io.Closer
}

Hook is a minimal interface that does not, and can't depend on Entry

type Options

type Options struct {
	ReadOnly bool
}

Options control the behavior of the cache

Jump to

Keyboard shortcuts

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