From 6635f874b2ae5ce2f793e7f935f78279b32c2e55 Mon Sep 17 00:00:00 2001
From: Ajit Jagtap <ajitj@mkcl.org>
Date: Mon, 9 Jul 2018 08:50:33 +0530
Subject: [PATCH] Changed Cache engine Changed YQL and andded new rule engine

---
 Gopkg.lock                                  |  81 +++++++++++-
 Gopkg.toml                                  |  28 ++++-
 cachemdl/cachemdl.go                        |  51 ++++++--
 cachemdl/cachemdl_test.go                   |   4 +-
 dalmdl/fdb/fdb.go                           |  17 +--
 dalmdl/fdb/fdb_test.go                      |  29 ++---
 dalmdl/fdb/fdbdefault.go                    |   4 +-
 main.go                                     |   5 +-
 servicebuildermdl/servicebuildermdl.go      |  40 +++++-
 servicebuildermdl/servicebuildermdl_test.go | 133 +++++++++++++++-----
 testingdata/users.json                      |   2 +-
 11 files changed, 303 insertions(+), 91 deletions(-)
 mode change 100755 => 100644 Gopkg.toml

diff --git a/Gopkg.lock b/Gopkg.lock
index 098728f..6219e30 100644
--- a/Gopkg.lock
+++ b/Gopkg.lock
@@ -1,6 +1,12 @@
 # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
 
 
+[[projects]]
+  name = "github.com/OneOfOne/xxhash"
+  packages = ["."]
+  revision = "6def279d2ce6c81a79dd1c1be580f03bb216fb8a"
+  version = "v1.2.2"
+
 [[projects]]
   branch = "master"
   name = "github.com/TylerBrock/colorjson"
@@ -41,6 +47,27 @@
   revision = "5b77d2a35fb0ede96d138fc9a99f5c9b6aef11b4"
   version = "v1.7.0"
 
+[[projects]]
+  branch = "master"
+  name = "github.com/gin-contrib/sse"
+  packages = ["."]
+  revision = "22d885f9ecc78bf4ee5d72b937e4bbcdc58e8cae"
+
+[[projects]]
+  name = "github.com/gin-gonic/gin"
+  packages = [
+    ".",
+    "binding",
+    "render"
+  ]
+  revision = "d459835d2b077e44f7c9b453505ee29881d5d12d"
+  version = "v1.2"
+
+[[projects]]
+  name = "github.com/golang/protobuf"
+  packages = ["proto"]
+  revision = "5a0f697c9ed9d68fef0116532c6e05cfeae00e55"
+
 [[projects]]
   name = "github.com/lithammer/fuzzysearch"
   packages = ["fuzzy"]
@@ -59,18 +86,40 @@
   revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
   version = "v0.0.3"
 
+[[projects]]
+  branch = "master"
+  name = "github.com/oleksandr/conditions"
+  packages = ["."]
+  revision = "8ed8af13bdec0d8ff0c0789842555e2c02181400"
+
 [[projects]]
   name = "github.com/op/go-logging"
   packages = ["."]
-  revision = "970db520ece77730c7e4724c61121037378659d9"
+  revision = "b2cb9fa56473e98db8caba80237377e83fe44db5"
   version = "v1"
 
+[[projects]]
+  name = "github.com/patrickmn/go-cache"
+  packages = ["."]
+  revision = "a3647f8e31d79543b2d0f0ae2fe5c379d72cedc0"
+  version = "v2.1.0"
+
 [[projects]]
   name = "github.com/pmezard/go-difflib"
   packages = ["difflib"]
   revision = "792786c7400a136282c1664665ae0a8db921c6c2"
   version = "v1.0.0"
 
+[[projects]]
+  branch = "master"
+  name = "github.com/pquerna/ffjson"
+  packages = [
+    "ffjson",
+    "fflib/v1",
+    "fflib/v1/internal"
+  ]
+  revision = "d49c2bc1aa135aad0c6f4fc2056623ec78f5d5ac"
+
 [[projects]]
   name = "github.com/segmentio/ksuid"
   packages = ["."]
@@ -100,6 +149,12 @@
   revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686"
   version = "v1.2.2"
 
+[[projects]]
+  name = "github.com/thedevsaddam/govalidator"
+  packages = ["."]
+  revision = "95c9c9c4864288c985e32eb32025819dae495c66"
+  version = "v1.9.1"
+
 [[projects]]
   name = "github.com/tidwall/gjson"
   packages = ["."]
@@ -112,11 +167,16 @@
   packages = ["."]
   revision = "1731857f09b1f38450e2c12409748407822dc6be"
 
+[[projects]]
+  name = "github.com/ugorji/go"
+  packages = ["codec"]
+  revision = "c88ee250d0221a57af388746f5cf03768c21d6e2"
+
 [[projects]]
   name = "go.uber.org/atomic"
   packages = ["."]
-  revision = "1ea20fb1cbb1cc08cbd0d913a96dead89aa18289"
-  version = "v1.3.2"
+  revision = "4e336646b2ef9fc6e47be8e21594178f98e5ebcf"
+  version = "v1.2.0"
 
 [[projects]]
   name = "go.uber.org/multierr"
@@ -141,7 +201,13 @@
   branch = "master"
   name = "golang.org/x/sys"
   packages = ["unix"]
-  revision = "151529c776cdc58ddbe7963ba9af779f3577b419"
+  revision = "3c6ecd8f22c6f40fbeec94c000a069d7d87c7624"
+
+[[projects]]
+  name = "gopkg.in/go-playground/validator.v8"
+  packages = ["."]
+  revision = "5f57d2222ad794d0dffb07e664ea05e2ee07d60c"
+  version = "v8.18.1"
 
 [[projects]]
   name = "gopkg.in/natefinch/lumberjack.v2"
@@ -149,9 +215,14 @@
   revision = "a96e63847dc3c67d17befa69c303767e2f84e54f"
   version = "v2.1"
 
+[[projects]]
+  name = "gopkg.in/yaml.v2"
+  packages = ["."]
+  revision = "a5b47d31c556af34a302ce5d659e6fea44d90de0"
+
 [solve-meta]
   analyzer-name = "dep"
   analyzer-version = 1
-  inputs-digest = "f827f9a5941a155c350f478743d55496318bffa114ba37c8501c894be1bce3dc"
+  inputs-digest = "1cbd22ebb55b11035a494e55f10ffcf976f37e47841b2b2c3e92344670e85c38"
   solver-name = "gps-cdcl"
   solver-version = 1
diff --git a/Gopkg.toml b/Gopkg.toml
old mode 100755
new mode 100644
index 9dfc503..577f35f
--- a/Gopkg.toml
+++ b/Gopkg.toml
@@ -25,6 +25,10 @@
 #   unused-packages = true
 
 
+[[constraint]]
+  name = "github.com/OneOfOne/xxhash"
+  version = "1.2.2"
+
 [[constraint]]
   branch = "master"
   name = "github.com/TylerBrock/colorjson"
@@ -34,17 +38,33 @@
   name = "github.com/bluele/gcache"
 
 [[constraint]]
-  name = "github.com/bndr/gotabulate"
-  version = "1.1.2"
+  branch = "master"
+  name = "github.com/caibirdme/yql"
+
+[[constraint]]
+  name = "github.com/gin-gonic/gin"
+  version = "1.2.0"
 
 [[constraint]]
   name = "github.com/lithammer/fuzzysearch"
   version = "1.0.1"
 
+[[constraint]]
+  branch = "master"
+  name = "github.com/oleksandr/conditions"
+
 [[constraint]]
   name = "github.com/op/go-logging"
   version = "1.0.0"
 
+[[constraint]]
+  name = "github.com/patrickmn/go-cache"
+  version = "2.1.0"
+
+[[constraint]]
+  branch = "master"
+  name = "github.com/pquerna/ffjson"
+
 [[constraint]]
   name = "github.com/segmentio/ksuid"
   version = "1.0.1"
@@ -57,6 +77,10 @@
   name = "github.com/stretchr/testify"
   version = "1.2.2"
 
+[[constraint]]
+  name = "github.com/thedevsaddam/govalidator"
+  version = "1.9.1"
+
 [[constraint]]
   name = "github.com/tidwall/gjson"
   version = "1.1.2"
diff --git a/cachemdl/cachemdl.go b/cachemdl/cachemdl.go
index 1196945..d3ad1cf 100755
--- a/cachemdl/cachemdl.go
+++ b/cachemdl/cachemdl.go
@@ -8,18 +8,19 @@ import (
 	"time"
 
 	"github.com/bluele/gcache"
+	"github.com/patrickmn/go-cache"
 )
 
-// CacheGCHelper use this to create new cache object
+// GCCacheHelper use this to create new cache object
 // Remember it holds memory
-type CacheGCHelper struct {
+type GCCacheHelper struct {
 	GC         gcache.Cache
 	Expiration time.Duration
 	MaxEntries int
 }
 
 //Setup create new object of GC
-func (gchelper *CacheGCHelper) Setup(MaxEntries int, Expiration time.Duration) {
+func (gchelper *GCCacheHelper) Setup(MaxEntries int, Expiration time.Duration) {
 	gchelper.MaxEntries = MaxEntries
 	gchelper.Expiration = Expiration
 	gchelper.GC = gcache.New(MaxEntries).
@@ -29,7 +30,7 @@ func (gchelper *CacheGCHelper) Setup(MaxEntries int, Expiration time.Duration) {
 
 //TODO: Check if you have SetUp value
 // //Setup create new object of GC
-// func (gchelper *CacheGCHelper) SetupWithCallbackFunction(MaxEntries int, Expiration time.Duration, f func(key interface{}, value interface{}) error) {
+// func (gchelper *GCCacheHelper) SetupWithCallbackFunction(MaxEntries int, Expiration time.Duration, f func(key interface{}, value interface{}) error) {
 // 	gchelper.MaxEntries = MaxEntries
 // 	gchelper.Expiration = Expiration
 // 	gchelper.GC = gcache.New(MaxEntries).
@@ -41,31 +42,61 @@ func (gchelper *CacheGCHelper) Setup(MaxEntries int, Expiration time.Duration) {
 // }
 
 //New Add new Key and value
-func (gchelper *CacheGCHelper) Set(key string, object interface{}) error {
+func (gchelper *GCCacheHelper) Set(key string, object interface{}) error {
 	return gchelper.GC.SetWithExpire(key, object, gchelper.Expiration)
 }
 
 //Get object based on key
-func (gchelper *CacheGCHelper) Get(key string) (interface{}, error) {
+func (gchelper *GCCacheHelper) Get(key string) (interface{}, error) {
 	return gchelper.GC.Get(key)
 }
 
 // GetAll objects from gc
-func (gchelper *CacheGCHelper) GetAll() map[interface{}]interface{} {
+func (gchelper *GCCacheHelper) GetAll() map[interface{}]interface{} {
 	return gchelper.GC.GetALL()
 }
 
 // Remove object from GC
-func (gchelper *CacheGCHelper) Remove(key string) bool {
+func (gchelper *GCCacheHelper) Remove(key string) bool {
 	return gchelper.GC.Remove(key)
 }
 
 //Purge all objects
-func (gchelper *CacheGCHelper) Purge() {
+func (gchelper *GCCacheHelper) Purge() {
 	gchelper.GC.Purge()
 }
 
 // Count all objects
-func (gchelper *CacheGCHelper) Count() int {
+func (gchelper *GCCacheHelper) Count() int {
 	return gchelper.GC.Len()
 }
+
+type FastCacheHelper struct {
+	FastCache   *cache.Cache
+	Expiration  time.Duration
+	CleanupTime time.Duration
+
+	MaxEntries int
+}
+
+//Setup create new object of GC
+func (fastCacheHelper *FastCacheHelper) Setup(maxEntries int, expiration time.Duration, cleanupTime time.Duration) {
+	fastCacheHelper.MaxEntries = maxEntries
+	fastCacheHelper.Expiration = expiration
+	fastCacheHelper.FastCache = cache.New(fastCacheHelper.Expiration, fastCacheHelper.CleanupTime)
+}
+
+func (fastCacheHelper *FastCacheHelper) Get(key string) (interface{}, bool) {
+	return fastCacheHelper.FastCache.Get(key)
+}
+
+func (fastCacheHelper *FastCacheHelper) SetNoExpiration(key string, object interface{}) {
+	fastCacheHelper.FastCache.Set(key, object, cache.NoExpiration)
+}
+func (fastCacheHelper *FastCacheHelper) Set(key string, object interface{}) {
+	fastCacheHelper.FastCache.Set(key, object, cache.DefaultExpiration)
+}
+
+func (fastCacheHelper *FastCacheHelper) Purge() {
+	fastCacheHelper.FastCache.Flush()
+}
diff --git a/cachemdl/cachemdl_test.go b/cachemdl/cachemdl_test.go
index f40ce59..022c403 100755
--- a/cachemdl/cachemdl_test.go
+++ b/cachemdl/cachemdl_test.go
@@ -9,10 +9,10 @@ import (
 	"github.com/stretchr/testify/assert"
 )
 
-var ch CacheGCHelper
+var ch GCCacheHelper
 
 func init() {
-	ch = CacheGCHelper{}
+	ch = GCCacheHelper{}
 	ch.Setup(500, time.Minute*50)
 }
 
diff --git a/dalmdl/fdb/fdb.go b/dalmdl/fdb/fdb.go
index 4ccfc88..ade311d 100755
--- a/dalmdl/fdb/fdb.go
+++ b/dalmdl/fdb/fdb.go
@@ -22,8 +22,8 @@ var (
 	NumberOfReads = 0
 	// NumberOfWrites Collects Number of Writes
 	NumberOfWrites = 0
-	// Mastercache Holds Cache for queries
-	Mastercache cachemdl.CacheGCHelper
+	// Fastcache Holds Cache for queries
+	Fastcache cachemdl.FastCacheHelper
 )
 
 // GetDataDAO will return query data
@@ -35,16 +35,14 @@ func GetDataDAO(filePath, query string, isCachable bool, rs gjson.Result) (gjson
 	}
 	if isCachable {
 
-		data, err := Mastercache.Get(filePath + query)
-		if errormdl.CheckErr(err) == nil {
+		data, found := Fastcache.Get(filePath + query)
+		if errormdl.CheckBool(found) {
 			val, ok := data.(gjson.Result)
-			if errormdl.CheckBool(ok) {
+			if errormdl.CheckBool1(ok) {
 				return val, nil
 			}
 			return gjson.Result{}, nil
-
 		}
-
 	}
 	byteData, err := getDataFromFDB(filePath)
 	if errormdl.CheckErr(err) != nil {
@@ -56,10 +54,7 @@ func GetDataDAO(filePath, query string, isCachable bool, rs gjson.Result) (gjson
 		rs = gjson.ParseBytes(byteData).Get(query)
 	}
 	if isCachable {
-		err := Mastercache.Set(filePath+query, rs)
-		if errormdl.CheckErr1(err) != nil {
-			return rs, errormdl.CheckErr1(err)
-		}
+		Fastcache.Set(filePath+query, rs)
 	}
 	return rs, nil
 }
diff --git a/dalmdl/fdb/fdb_test.go b/dalmdl/fdb/fdb_test.go
index d1be8ed..4501e4d 100755
--- a/dalmdl/fdb/fdb_test.go
+++ b/dalmdl/fdb/fdb_test.go
@@ -27,40 +27,25 @@ func TestGetDataDAO_WithRaw(t *testing.T) {
 	result, err = GetDataDAO("../../testingdata/users.json", "*", true, result)
 	assert.NoError(t, err, "This should not return error")
 }
+
 func TestGetDataDAO_WithFileReadError(t *testing.T) {
 	errormdl.IsTestingNegetiveCaseOn = true
-	_, err := GetDataDAO("../../testingdata/users.json", "*", true, gjson.Result{})
-	assert.Error(t, err, "This should not return error")
+	_, err := GetDataDAO("../../testingdata/users.json", "*", false, gjson.Result{})
+	assert.Error(t, err, "This should  return error")
 }
 
 func TestGetDataDAO_WithFileRead(t *testing.T) {
 	//no error and cache flush
-	Mastercache.Purge()
+	Fastcache.Purge()
 	errormdl.IsTestingNegetiveCaseOn = false
 	_, err := GetDataDAO("../../testingdata/users.json", "#", true, gjson.Result{})
 	assert.NoError(t, err, "This should not return error")
 }
 
-func TestGetDataDAO_WithFileReadWithCacheSetErr(t *testing.T) {
+func TestGetDataDAO_WithCacheGetErrAndFileRead(t *testing.T) {
 	//no error and cache flush
-	Mastercache.Purge()
-	errormdl.IsTestingNegetiveCaseOn = false
-	errormdl.IsTestingNegetiveCaseOn1 = true
-	_, err := GetDataDAO("../../testingdata/users.json", "#", true, gjson.Result{})
-	assert.Error(t, err, "This should not return error")
-}
-func TestGetDataDAO_WithFileReadWithCacheSetErrAssertionError(t *testing.T) {
-
-	// Clear Data
-	Mastercache.Purge()
-
-	// fail on negetive case false
-	errormdl.IsTestingNegetiveCaseOn = false
-	//check bool false
+	Fastcache.Purge()
 	errormdl.IsTestingNegetiveCaseOnCheckBool = true
 	_, err := GetDataDAO("../../testingdata/users.json", "#", true, gjson.Result{})
-	assert.Error(t, err, "This should not return error")
-	errormdl.IsTestingNegetiveCaseOnCheckBool = true
-	resultobj, _ := GetDataDAO("../../testingdata/users.json", "#", true, gjson.Result{})
-	assert.NotNil(t, resultobj, "This should not return error")
+	assert.NoError(t, err, "This should not return error")
 }
diff --git a/dalmdl/fdb/fdbdefault.go b/dalmdl/fdb/fdbdefault.go
index ef25684..453e3f4 100755
--- a/dalmdl/fdb/fdbdefault.go
+++ b/dalmdl/fdb/fdbdefault.go
@@ -13,7 +13,7 @@ import (
 )
 
 func init() {
-	Mastercache = cachemdl.CacheGCHelper{}
+	Fastcache = cachemdl.FastCacheHelper{}
 	//FIXME: Below hardcoded values need better number
-	Mastercache.Setup(5000, time.Second*500)
+	Fastcache.Setup(5000, time.Minute*500, time.Minute*500)
 }
diff --git a/main.go b/main.go
index d8fa929..5b82e36 100644
--- a/main.go
+++ b/main.go
@@ -1,7 +1,10 @@
 package main
 
-import "fmt"
+import (
+	"fmt"
+)
 
 func main() {
 	fmt.Println("hello")
+
 }
diff --git a/servicebuildermdl/servicebuildermdl.go b/servicebuildermdl/servicebuildermdl.go
index b60d8ec..383aecd 100644
--- a/servicebuildermdl/servicebuildermdl.go
+++ b/servicebuildermdl/servicebuildermdl.go
@@ -1,13 +1,21 @@
 package servicebuildermdl
 
 import (
+	"strings"
+
 	"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/errormdl"
 	"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/loggermdl"
-	"github.com/tidwall/gjson"
 
-	"github.com/caibirdme/yql"
+	"github.com/oleksandr/conditions"
+	"github.com/tidwall/gjson"
 )
 
+var ruleCache map[string]conditions.Expr
+
+func init() {
+	ruleCache = make(map[string]conditions.Expr, 0)
+}
+
 // LoadData is a method sign for loader methods
 type LoadData = func(ab *AbstractBusinessLogicHolder)
 
@@ -49,7 +57,7 @@ func (ab *AbstractBusinessLogicHolder) GetDataInt(key string) (int, bool) {
 	return value, true
 }
 
-// GetBool will give you int
+// GetResultset will give you int
 func (ab *AbstractBusinessLogicHolder) GetResultset(key string) (*gjson.Result, bool) {
 	//check in map
 	temp, found := ab.ServiceData[key]
@@ -97,7 +105,7 @@ func (ab *AbstractBusinessLogicHolder) Build() {
 	ab.ServiceData = make(map[string]interface{})
 }
 
-// SetGJSON will return map data with finaldata key
+// SetResultset will return map data with finaldata key
 func (ab *AbstractBusinessLogicHolder) SetResultset(key string, obj *gjson.Result) {
 	ab.ServiceData[key] = obj
 }
@@ -108,7 +116,7 @@ func (ab *AbstractBusinessLogicHolder) GetFinalData() *interface{} {
 	return &a
 }
 
-// GetFinalData will return map data with finaldata key
+// SetFinalData will return map data with finaldata key
 func (ab *AbstractBusinessLogicHolder) SetFinalData(data interface{}) {
 	ab.ServiceData["finaldata"] = data
 }
@@ -125,6 +133,7 @@ func (ab *AbstractBusinessLogicHolder) EchoBL() map[string]interface{} {
 type Step struct {
 	Stepname        string
 	RawYQL          string
+	expr            conditions.Expr
 	processDataFunc LoadData
 	RunFunc         func() map[string]interface{}
 	ErrorFunc       func() map[string]interface{}
@@ -153,6 +162,24 @@ func GetSB(name string, ab *AbstractBusinessLogicHolder) *ServiceBuilder {
 func (sb *ServiceBuilder) AddStep(stepname, rule string, ld LoadData, blfunc, errorfunc func() map[string]interface{}) *ServiceBuilder {
 	step := Step{}
 	step.RawYQL = rule
+
+	//Check rule in cache
+	cachedRule, found := ruleCache[rule]
+	if !found {
+		step.expr = cachedRule
+	} else {
+
+		// Parse the condition language and get expression
+		p := conditions.NewParser(strings.NewReader(rule))
+		expr, err := p.Parse()
+		if err != nil {
+			step.expr = expr
+		} else {
+			loggermdl.LogError("Error in step expr", err)
+		}
+		ruleCache[rule] = expr
+	}
+
 	step.RunFunc = blfunc
 	step.ErrorFunc = errorfunc
 	step.Stepname = stepname
@@ -172,7 +199,8 @@ func (sb *ServiceBuilder) Run() *ServiceBuilder {
 
 		//Run step func
 		tmp := step.RunFunc()
-		result, _ := yql.Match(step.RawYQL, tmp)
+		// result, _ := yql.Match(step.RawYQL, tmp)
+		result, _ := conditions.Evaluate(step.expr, tmp)
 		if !result {
 			// loggermdl.LogWarn(step.Stepname, "Failed", result)
 			step.ErrorFunc()
diff --git a/servicebuildermdl/servicebuildermdl_test.go b/servicebuildermdl/servicebuildermdl_test.go
index 0959456..ab47398 100644
--- a/servicebuildermdl/servicebuildermdl_test.go
+++ b/servicebuildermdl/servicebuildermdl_test.go
@@ -1,17 +1,41 @@
 package servicebuildermdl
 
 import (
+	"strings"
 	"testing"
+	"time"
 
+	"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/cachemdl"
 	"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/loggermdl"
 
 	dalmdl "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/dalmdl/dao"
 
-	"github.com/caibirdme/yql"
+	"github.com/oleksandr/conditions"
+	cache "github.com/patrickmn/go-cache"
 	"github.com/stretchr/testify/assert"
 	"github.com/tidwall/gjson"
 )
 
+var fastCache cachemdl.FastCacheHelper
+var loaddata LoadData
+var mb MyBLLayer
+var s ServiceBuilder
+
+func init() {
+	fastCache = cachemdl.FastCacheHelper{}
+	fastCache.Setup(5000, time.Minute*500, time.Minute*500)
+
+	mb = MyBLLayer{}
+	mb.Build()
+
+	loaddata = func(ab *AbstractBusinessLogicHolder) {
+		mb.ServiceData["daodata1"] = GetUsersInfo()
+	}
+
+	GetSB("mysrv", &mb.AbstractBusinessLogicHolder).
+		AddStep("Check Mobile", "owner in ('SystemIntegrator')", loaddata, mb.FindAndVerifyMobileNumber, mb.EchoBL)
+}
+
 //Create Type with abstract Type
 type MyBLLayer struct {
 	AbstractBusinessLogicHolder
@@ -20,13 +44,20 @@ type MyBLLayer struct {
 // attach methods to it
 func (m *MyBLLayer) FindAndVerifyMobileNumber() map[string]interface{} {
 	loginID := "noone"
-	result1, ok := m.GetResultset("daodata1")
 
-	if !ok {
-		loggermdl.LogError("error in convert")
-	}
+	//check in cache
+	fresult, okay := fastCache.Get("#[mobileNo==\"7875383220\"].loginId")
+	if okay {
+		loginID = fresult.(string)
+	} else {
+		result1, ok := m.GetResultset("daodata1")
 
-	loginID = result1.Get("#[mobileNo==\"7875383220\"].loginId").String()
+		if !ok {
+			loggermdl.LogError("error in convert")
+		}
+		loginID = result1.Get("#[mobileNo==\"7875383220\"].loginId").String()
+		fastCache.Set("#[mobileNo==\"7875383220\"].loginId", loginID)
+	}
 
 	m.SetFinalData(loginID)
 
@@ -55,7 +86,7 @@ func TestService(t *testing.T) {
 	// }
 
 	sb := GetSB("mysrv", &mb.AbstractBusinessLogicHolder).
-		AddStep("Check Mobile", "owner in ('SystemIntegrator')", loaddata, mb.FindAndVerifyMobileNumber, mb.EchoBL).
+		AddStep("Check Mobile", "owner = 'SystemIntegrator')", loaddata, mb.FindAndVerifyMobileNumber, mb.EchoBL).
 		AddStep("Test STEP 2", "owner = 'SystemIntegrator'", nil, mb.FindAndVerifyMobileNumber, mb.EchoBL).
 		Run().FinalOutput(nil)
 
@@ -64,41 +95,85 @@ func TestService(t *testing.T) {
 
 func BenchmarkService(b *testing.B) {
 	for index := 0; index < b.N; index++ {
-		mb := MyBLLayer{}
-		mb.Build()
-
-		loaddata := func(ab *AbstractBusinessLogicHolder) {
-			mb.ServiceData["daodata1"] = GetUsersInfo()
-		}
 
 		// finalStep := func(ab *AbstractBusinessLogicHolder) *interface{} {
 		// 	s :=
 		// 	return &s
 		// }
+		s.Run() //.FinalOutput(nil)
+	}
+
+}
 
-		GetSB("mysrv", &mb.AbstractBusinessLogicHolder).
-			AddStep("Check Mobile", "owner in ('SystemIntegrator')", loaddata, mb.FindAndVerifyMobileNumber, mb.EchoBL).
-			AddStep("Test STEP 2", "owner = 'SystemIntegrator'", nil, mb.FindAndVerifyMobileNumber, mb.EchoBL).
-			Run().FinalOutput(nil)
+// func BenchmarkTestYQL(b *testing.B) {
+// 	for index := 0; index < b.N; index++ {
+// 		a := map[string]interface{}{
+// 			"cnt": 16,
+// 		}
+// 		result, _ := yql.Match("cnt > 3)", a)
+// 		if result {
+
+// 		}
+// 	}
+// 	// assert.Equal(t, true, result, "Yql should work")
+// }
+
+func BenchmarkRuleEngine2(b *testing.B) {
+	for index := 0; index < b.N; index++ {
+
+		// Our condition to check
+		s := "cnt > 0.45"
+
+		// Parse the condition language and get expression
+		p := conditions.NewParser(strings.NewReader(s))
+		expr, err := p.Parse()
+		if err != nil {
+			// ...
+		}
+
+		// Evaluate expression passing data for $vars
+		data := map[string]interface{}{"cnt": 0.99, "$1": "ON", "$2": "ACTIVE", "$3": false}
+		a, err := conditions.Evaluate(expr, data)
+		if a != false {
+			// ...
+		}
+
+		// r is false
+		// fmt.Println("Evaluation result:", r)
 	}
 
 }
 
-func TestYQL(t *testing.T) {
-	a := map[string]interface{}{
-		"owner": "a",
+func BenchmarkCache1(b *testing.B) {
+	c := cache.New(5*time.Minute, 10*time.Minute)
+	// Set the value of the key "foo" to "bar", with the default expiration time
+	c.Set("foo", "bar", cache.DefaultExpiration)
+
+	for index := 0; index < b.N; index++ {
+
+		// Get the string associated with the key "foo" from the cache
+		_, found := c.Get("foo")
+		if found {
+			// fmt.Println(foo)
+		}
 	}
-	result, _ := yql.Match("owner ='a')", a)
-	assert.Equal(t, true, result, "Yql should work")
+
 }
 
-func TestPanic(t *testing.T) {
-	var a interface{}
-	a = nil
-	// a= nil
+func BenchmarkCache2(b *testing.B) {
+	// var Mastercache cachemdl.CacheGCHelper
+	// Mastercache := cachemdl.FastCacheHelper{}
+	// Mastercache.Setup(5000, time.Second*500)
+	// // Set the value of the key "foo" to "bar", with the default expiration time
+	// Mastercache.Set("foo", 1)
 
-	_, ok := a.(string)
-	assert.False(t, ok, "should panic")
-	// assert.Equal(t, "something", s, "should be same")
+	// for index := 0; index < b.N; index++ {
+
+	// 	// Get the string associated with the key "foo" from the cache
+	// 	_, found := Mastercache.Get("foo")
+	// 	if found == nil {
+	// 		// fmt.Println(foo)
+	// 	}
+	// }
 
 }
diff --git a/testingdata/users.json b/testingdata/users.json
index d9b5bbb..daa7167 100755
--- a/testingdata/users.json
+++ b/testingdata/users.json
@@ -20,7 +20,7 @@
 	"emailId": "roshanp@mkcl.org",
 	"password": "roshanp",
 	"oldPassword": "",
-	"mobileNo": "8421553539",
+	"mobileNo": "84211553539",
 	"isEnabled": true,
 	"confirmPassword": "",
 	"path": "4463acaefbcf3e6511883f9d4f0b6076.jpg",
-- 
GitLab