cache

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 12 Imported by: 9

Documentation

Overview

Package cache provides a cache of model.Model elements that can be used in an OVSDB client or server.

The cache can be accessed using a simple API:

cache.Table("Open_vSwitch").Row("<ovs-uuid>")

It implements the ovsdb.NotificationHandler interface such that it can be populated automatically by update notifications

It also contains an eventProcessor where callers may registers functions that will get called on every Add/Update/Delete event.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data map[string]map[string]model.Model

Data is the type for data that can be prepoulated in the cache

type EventHandler

type EventHandler interface {
	OnAdd(table string, model model.Model)
	OnUpdate(table string, old model.Model, new model.Model)
	OnDelete(table string, model model.Model)
}

EventHandler can handle events when the contents of the cache changes

type EventHandlerFuncs

type EventHandlerFuncs struct {
	AddFunc    func(table string, model model.Model)
	UpdateFunc func(table string, old model.Model, new model.Model)
	DeleteFunc func(table string, model model.Model)
}

EventHandlerFuncs is a wrapper for the EventHandler interface It allows a caller to only implement the functions they need

func (*EventHandlerFuncs) OnAdd

func (e *EventHandlerFuncs) OnAdd(table string, model model.Model)

OnAdd calls AddFunc if it is not nil

func (*EventHandlerFuncs) OnDelete

func (e *EventHandlerFuncs) OnDelete(table string, row model.Model)

OnDelete calls DeleteFunc if it is not nil

func (*EventHandlerFuncs) OnUpdate

func (e *EventHandlerFuncs) OnUpdate(table string, old, new model.Model)

OnUpdate calls UpdateFunc if it is not nil

type IndexExistsError

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

func NewIndexExistsError

func NewIndexExistsError(table string, value interface{}, index index, new, existing string) *IndexExistsError

func (*IndexExistsError) Error

func (i *IndexExistsError) Error() string

type RowCache

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

RowCache is a collections of Models hashed by UUID

func (*RowCache) Create

func (r *RowCache) Create(uuid string, m model.Model, checkIndexes bool) error

Create writes the provided content to the cache

func (*RowCache) Delete

func (r *RowCache) Delete(uuid string) error

Delete deletes a row from the cache

func (*RowCache) Index

func (r *RowCache) Index(columns ...string) (map[interface{}]string, error)

func (*RowCache) Len

func (r *RowCache) Len() int

Len returns the length of the cache

func (*RowCache) Row

func (r *RowCache) Row(uuid string) model.Model

Row returns one model from the cache by UUID

func (*RowCache) RowByModel added in v0.6.0

func (r *RowCache) RowByModel(m model.Model) model.Model

RowByModel searches the cache using a the indexes for a provided model

func (*RowCache) Rows

func (r *RowCache) Rows() []string

Rows returns a list of row UUIDs as strings

func (*RowCache) Update

func (r *RowCache) Update(uuid string, m model.Model, checkIndexes bool) error

Update updates the content in the cache

type TableCache

type TableCache struct {
	ovsdb.NotificationHandler
	// contains filtered or unexported fields
}

TableCache contains a collection of RowCaches, hashed by name, and an array of EventHandlers that respond to cache updates It implements the ovsdb.NotifcationHandler interface so it may handle update notifications

func NewTableCache

func NewTableCache(schema *ovsdb.DatabaseSchema, dbModel *model.DBModel, data Data) (*TableCache, error)

NewTableCache creates a new TableCache

func (*TableCache) AddEventHandler

func (t *TableCache) AddEventHandler(handler EventHandler)

AddEventHandler registers the supplied EventHandler to receive cache events

func (*TableCache) CreateModel

func (t *TableCache) CreateModel(tableName string, row *ovsdb.Row, uuid string) (model.Model, error)

CreateModel creates a new Model instance based on the Row information

func (*TableCache) DBModel

func (t *TableCache) DBModel() *model.DBModel

DBModel returns the DBModel

func (*TableCache) Disconnected

func (t *TableCache) Disconnected()

Disconnected implements the disconnected method of the NotificationHandler interface

func (*TableCache) Echo

func (t *TableCache) Echo([]interface{})

Echo implements the echo method of the NotificationHandler interface

func (*TableCache) Locked

func (t *TableCache) Locked([]interface{})

Locked implements the locked method of the NotificationHandler interface

func (*TableCache) Mapper

func (t *TableCache) Mapper() *mapper.Mapper

Mapper returns the mapper

func (*TableCache) Populate

func (t *TableCache) Populate(tableUpdates ovsdb.TableUpdates)

Populate adds data to the cache and places an event on the channel

func (*TableCache) Purge added in v0.6.0

func (t *TableCache) Purge(schema *ovsdb.DatabaseSchema)

Purge drops all data in the cache and reinitializes it using the provided schema

func (*TableCache) Run

func (t *TableCache) Run(stopCh <-chan struct{})

Run starts the event processing loop. It blocks until the channel is closed.

func (*TableCache) Stolen

func (t *TableCache) Stolen([]interface{})

Stolen implements the stolen method of the NotificationHandler interface

func (*TableCache) Table

func (t *TableCache) Table(name string) *RowCache

Table returns the a Table from the cache with a given name

func (*TableCache) Tables

func (t *TableCache) Tables() []string

Tables returns a list of table names that are in the cache

func (*TableCache) Update

func (t *TableCache) Update(context interface{}, tableUpdates ovsdb.TableUpdates)

Update implements the update method of the NotificationHandler interface this populates the cache with new updates

Jump to

Keyboard shortcuts

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