From b589342503421f0d4983b74d7a0701442fe65cac Mon Sep 17 00:00:00 2001 From: "Sandeep S. Shewalkar" <sandeepss@mkcl.org> Date: Thu, 22 Jun 2017 14:41:42 +0530 Subject: [PATCH] Update cacvar bigcacheConfig = bigcache.Config{heHelper.go --- cacheHelper.go | 126 ++++++++++++++++++++++++------------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/cacheHelper.go b/cacheHelper.go index 1b93ec0..9d3eebc 100644 --- a/cacheHelper.go +++ b/cacheHelper.go @@ -1,63 +1,63 @@ -package coreos - -import ( - "fmt" - "time" - - "github.com/allegro/bigcache" -) - - -const ( - BIGCACHEShards=8 - BIGCACHEMaxEntrySize=1024 - BIGCACHEVerbose=true - BIGCACHEHardMaxCacheSize=0 - BIGCACHEMaxEntriesInWindow=1000 10 60 - BIGCACHELifeWindow=2 -) -var bigcacheConfig = bigcache.Config{ - // number of shards (must be a power of 2) - // Shards: 4096, - Shards: BIGCACHEShards, - // time after which entry can be evicted - LifeWindow: BIGCACHELifeWindow * time.Hour, - // rps * lifeWindow, used only in initial memory allocation - MaxEntriesInWindow: 1000 * 10 * 60, - // MaxEntriesInWindow: 10, - // max entry size in bytes, used only in initial memory allocation - MaxEntrySize: BIGCACHEMaxEntrySize, - // prints information about additional memory allocation - Verbose: BIGCACHEVerbose, - // cache will not allocate more memory than this limit, value in MB - // if value is reached then the oldest entries can be overridden for the new ones - // 0 value means no size limit - HardMaxCacheSize: BIGCACHEHardMaxCacheSize, - // callback fired when the oldest entry is removed because of its - // expiration time or no space left for the new entry. Default value is nil which - // means no callback and it prevents from unwrapping the oldest entry. - OnRemove: nil, -} - -var cache, initErr = bigcache.NewBigCache(bigcacheConfig) - -//GetValue GetValue -func GetValue(key string) ([]byte, error) { - return cache.Get(key) -} - -//SetValue SetValue -func SetValue(key string, value []byte) { - cache.Set(key, value) -} - -//GetLength GetLength -func GetLength() int { - return cache.Len() -} - -//Callback function executed when cache element is removed. -//Executed only when onRemove of cache config poting to this function -func onRemove(key string, entry []byte) { - fmt.Println(key + " removed at " + time.Now().String()) -} +package coreos + +import ( + "fmt" + "time" + + "github.com/allegro/bigcache" +) + + +const ( + BIGCACHEShards=8 + BIGCACHEMaxEntrySize=1024 + BIGCACHEVerbose=true + BIGCACHEHardMaxCacheSize=0 + BIGCACHEMaxEntriesInWindow=1000 10 60 + BIGCACHELifeWindow=2 +) +var bigcacheConfig = bigcache.Config{ + // number of shards (must be a power of 2) + // Shards: 4096, + Shards: BIGCACHEShards, + // time after which entry can be evicted + LifeWindow: BIGCACHELifeWindow * time.Hour, + // rps * lifeWindow, used only in initial memory allocation + MaxEntriesInWindow: 1000 * 10 * 60, + // MaxEntriesInWindow: 10, + // max entry size in bytes, used only in initial memory allocation + MaxEntrySize: BIGCACHEMaxEntrySize, + // prints information about additional memory allocation + Verbose: BIGCACHEVerbose, + // cache will not allocate more memory than this limit, value in MB + // if value is reached then the oldest entries can be overridden for the new ones + // 0 value means no size limit + HardMaxCacheSize: BIGCACHEHardMaxCacheSize, + // callback fired when the oldest entry is removed because of its + // expiration time or no space left for the new entry. Default value is nil which + // means no callback and it prevents from unwrapping the oldest entry. + OnRemove: nil, +} + +var cache, initErr = bigcache.NewBigCache(bigcacheConfig) + +//GetValue GetValue +func GetValue(key string) ([]byte, error) { + return cache.Get(key) +} + +//SetValue SetValue +func SetValue(key string, value []byte) { + cache.Set(key, value) +} + +//GetLength GetLength +func GetLength() int { + return cache.Len() +} + +//Callback function executed when cache element is removed. +//Executed only when onRemove of cache config poting to this function +func onRemove(key string, entry []byte) { + fmt.Println(key + " removed at " + time.Now().String()) +} -- GitLab