Commit e551e7b1 authored by Akshay Bharambe's avatar Akshay Bharambe
Browse files

Add: Expose current cache instance.

parent 4e74a6af
Branches
Tags
2 merge requests!173Mep release19032020,!170Add: Functionality to call session manager from bls.
Showing with 27 additions and 2 deletions
......@@ -17,6 +17,14 @@ var (
ErrInvalidCacheType = errors.New("invalid cache type provided")
)
var (
// Set @Setup(), CacheInUse provides current cache in use. We can take decision to perform cache specific operations with this.
CacheInUse int
// Set @setup(), if true, cache is already initialized
initialized bool
)
// Cacher provides access to underlying cache, make sure all caches implement these methods.
type Cacher interface {
// SET
......
......@@ -52,8 +52,13 @@ type RedisCache struct {
Prefix string // this will be used for storing keys for provided project
}
// Setup -
// Setup initializes redis cache for application. Must be called only once.
func (rc *RedisCache) Setup(addr, password, prefix string, db int, exp time.Duration) {
if initialized {
loggermdl.LogError("cache instance is already initialized")
return
}
if rc == nil {
rc = new(RedisCache)
}
......@@ -84,6 +89,9 @@ func (rc *RedisCache) Setup(addr, password, prefix string, db int, exp time.Dura
rc.keyStr = contcat(rc.Prefix, keySplitter)
rc.addPrefix = true
}
CacheInUse = TypeRedisCache
initialized = true
}
// Set marshalls provided value and stores against provided key. Errors will be logged to initialized logger.
......
......@@ -7,6 +7,7 @@ package cachemdl
import (
"time"
"corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/loggermdl"
"github.com/patrickmn/go-cache"
)
......@@ -19,11 +20,19 @@ type FastCacheHelper struct {
MaxEntries int
}
//Setup create new object of GC
// Setup initializes fastcache cache for application. Must be called only once.
func (fastCacheHelper *FastCacheHelper) Setup(maxEntries int, expiration time.Duration, cleanupTime time.Duration) {
if initialized {
loggermdl.LogError("cache instance is already initialized")
return
}
fastCacheHelper.MaxEntries = maxEntries
fastCacheHelper.Expiration = expiration
fastCacheHelper.FastCache = cache.New(fastCacheHelper.Expiration, fastCacheHelper.CleanupTime)
CacheInUse = TypeFastCache
initialized = true
}
// Get -
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment