VOL-1584: Fix for multi-core cli infinite loop

- Reduced number of calls to kv
- Re-introduced cache logic for in-memory data access
- Misc log updates

Amendments:

- Ensure that we clone the returned cache data
- Give priority to cache but use alternate get methods otherwise

Change-Id: I56ce67f22d9945b7a194f4c6aab0c7fd75dd2f2e
diff --git a/db/model/non_persisted_revision.go b/db/model/non_persisted_revision.go
index 0ccc58e..d7b0b58 100644
--- a/db/model/non_persisted_revision.go
+++ b/db/model/non_persisted_revision.go
@@ -21,30 +21,28 @@
 	"fmt"
 	"github.com/golang/protobuf/proto"
 	"github.com/opencord/voltha-go/common/log"
+	"github.com/opencord/voltha-go/db/kvstore"
 	"reflect"
-	"runtime/debug"
 	"sort"
 	"sync"
 )
 
 // TODO: Cache logic will have to be revisited to cleanup unused entries in memory (disabled for now)
 //
-//type revCacheSingleton struct {
-//	sync.RWMutex
-//	//Cache map[string]interface{}
-//	Cache sync.Map
-//}
-//
-//var revCacheInstance *revCacheSingleton
-//var revCacheOnce sync.Once
-//
-//func GetRevCache() *revCacheSingleton {
-//	revCacheOnce.Do(func() {
-//		//revCacheInstance = &revCacheSingleton{Cache: make(map[string]interface{})}
-//		revCacheInstance = &revCacheSingleton{Cache: sync.Map{}}
-//	})
-//	return revCacheInstance
-//}
+type revCacheSingleton struct {
+	sync.RWMutex
+	Cache sync.Map
+}
+
+var revCacheInstance *revCacheSingleton
+var revCacheOnce sync.Once
+
+func GetRevCache() *revCacheSingleton {
+	revCacheOnce.Do(func() {
+		revCacheInstance = &revCacheSingleton{Cache: sync.Map{}}
+	})
+	return revCacheInstance
+}
 
 type NonPersistedRevision struct {
 	mutex        sync.RWMutex
@@ -409,7 +407,7 @@
 
 // Drop is used to indicate when a revision is no longer required
 func (npr *NonPersistedRevision) Drop(txid string, includeConfig bool) {
-	log.Debugw("dropping-revision", log.Fields{"hash": npr.GetHash(), "stack": string(debug.Stack())})
+	log.Debugw("dropping-revision", log.Fields{"hash": npr.GetHash(), "name": npr.GetName()})
 	npr.discarded = true
 }
 
@@ -428,7 +426,7 @@
 	}
 }
 
-func (npr *NonPersistedRevision) LoadFromPersistence(path string, txid string) []Revision {
+func (npr *NonPersistedRevision) LoadFromPersistence(path string, txid string, blobs map[string]*kvstore.KVPair) []Revision {
 	// stub... required by interface
 	return nil
 }