mem

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package mem provides in-memory implementation of the mapping with multiple indexes.

To create new mapping run:

	   import "github.com/ligato/cn-infra/idxmap/mem"

    mapping := mem.NewNamedMapping(logger, "owner", "title", indexFunc)

Owner and title are used for identification of the mapping. IndexFunc extracts secondary indexes from the stored item.

To insert a new item into the mapping, execute:

mapping.Put(name, value)

Put can also be used to overwrite an existing item associated with the name.

To retrieve a particular item identified by name run:

meta, found := mapping.Lookup(name)

To lookup items by secondary indexes, execute:

names := mapping.LookupByMetadata(indexName, indexValue)

names of all matching items are returned.

To retrieve all currently registered names, run:

names := mapping.ListNames()

If you want to remove an item from the mapping:

mapping.Delete(name)

To monitor changes, run:

   callback := func(notif idxmap.NamedMappingDto) {
		   // process notification
	  }

   mapping.Watch("NameOfWatcher", callback)

If you prefer processing changes through channels:

ch := make(chan idxmap.NamedMappingDto)
mapping.Watch("NameOfWatcher", ToChan(ch))

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNamedMapping

func NewNamedMapping(logger logging.Logger, owner core.PluginName, title string,
	indexFunction func(interface{}) map[string][]string) idxmap.NamedMappingRW

NewNamedMapping creates a new instance of the in-memory implementation of idxmap.NamedMappingRW An index function that creates secondary indexes can be defined.

Types

type CacheHelper

type CacheHelper struct {
	IDX           idxmap.NamedMappingRW
	Prefix        string
	DataPrototype proto.Message
	ParseName     func(key string) (name string, err error)
}

CacheHelper is a helper which implementation is reused among multiple typesafe Caches.

func (*CacheHelper) DoChange

func (helper *CacheHelper) DoChange(dataChng datasync.ChangeEvent) error

DoChange calls: - Put in case of datasync.Put - Delete in case of data.Del

func (*CacheHelper) DoResync

func (helper *CacheHelper) DoResync(resyncEv datasync.ResyncEvent) error

DoResync list keys&values in ResyncEvent and then: - Put (for names that are part of ResyncEvent) - Delete (for names that are not part of ResyncEvent)

func (*CacheHelper) DoWatching

func (helper *CacheHelper) DoWatching(resyncName string, watcher datasync.KeyValProtoWatcher)

DoWatching is supposed to be used as a go routine. It select the data from channels in arguments.

func (*CacheHelper) String

func (helper *CacheHelper) String() string

Jump to

Keyboard shortcuts

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