cn-infra: github.com/ligato/cn-infra/idxmap/mem Index | Files

package mem

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

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, "title", indexFunc)

Title is 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 and to rebuild secondary indexes for that item.

To retrieve a particular item identified by name run:

value, found := mapping.GetValue(name)

To lookup items by secondary indexes, execute:

names := mapping.ListNames(indexName, indexValue)

names of all matching items are returned.

To retrieve all currently registered names, run:

names := mapping.ListAllNames()

If you want to remove an item from the mapping, call:

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.NamedMappingGenericEvent)
mapping.Watch("NameOfWatcher", ToChan(ch))

Index

Package Files

cache_helper.go doc.go inmemory_name_mapping.go

func NewNamedMapping Uses

func NewNamedMapping(logger logging.Logger, title string,
    indexFunction IndexFunction) idxmap.NamedMappingRW

NewNamedMapping creates a new instance of the in-memory implementation of idxmap.NamedMappingRW An index function that builds secondary indexes for an item can be defined and passed as <indexFunction>.

type CacheHelper Uses

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

CacheHelper is a base cache implementation reused by multiple typesafe Caches.

func (*CacheHelper) DoChange Uses

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

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

func (*CacheHelper) DoResync Uses

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 Uses

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

DoWatching reflects data change and data resync events received from <watcher> into the idxmap.

func (*CacheHelper) String Uses

func (helper *CacheHelper) String() string

String returns the cache prefix.

type IndexFunction Uses

type IndexFunction func(item interface{}) map[string][]string

IndexFunction should return map field->values for a given item.

Package mem imports 6 packages (graph) and is imported by 13 packages. Updated 2019-12-14. Refresh now. Tools for package owners.