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, "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 ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewNamedMapping ¶
func NewNamedMapping(logger logging.Logger, 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 builds secondary indexes for an item can be defined and passed as <indexFunction>.
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 base cache implementation reused by 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 reflects data change and data resync events received from <watcher> into the idxmap.
func (*CacheHelper) String ¶
func (helper *CacheHelper) String() string
String returns the cache prefix.